get

In Flamingo templates/snippets, the get predefined keyword can be used to obtain parameters in the context of the current node.

You can use it to get node attributes and/or HTML content . The value it returns can be string or array. In case of array, you can work with it as with ordinary array.

If the defined value does not exist, NULL is returned.

Getting Attributes

As stated above, you can get node attributes. For this, you should define the attribute you need to get starting it with the @ (‘At’ sign) symbol in the parameter collection and start it with the _ (underscore) symbol in the template/snippet code.

Code on the desktop site page:

<html>
 <body>
   <img src="image.jpg" />
 </body>
</html>

Defining action to get src and alt attributes in the parameters collection in Flamingo IDE:

{
 image: {
   xpath: '//img',
   get:   ['@src', '@alt']
 }
}

Code in your template/snippet to obtain the value of the src and alt attributes:

<!--{= $.image._src }-->


<!--{= $.image._alt }-->

Note that NULL will be returned as alt attribute value, because this attribute is not available on the desktop site page.

Special values for getting HTML content

With get, you can use special values to obtain different information from the desktop site.

text

Use this value to obtain text of the current node. Code on the desktop site page:

<html>
 <body>
   <p>Sample text. <img src="image.jpg" alt="" id="image" /></p>
 </body>
</html>

Defining action to get text in the parameters collection in Flamingo IDE:

{
 para: {
   xpath: '//p',
   get:   'text'
 }
}

Now when you use the para parameter in your template/snippet code, the text “Sample text.” will be returned.

html

Use this special value to obtain string with HTML code of the current node.

Code on the desktop site page:

<html>
 <body>
   <p>Sample text. <img src="image.jpg" alt="" id="image" /></p>
 </body>
</html>

Defining action to get HTML in the parameters collection in Flamingo IDE:

{
 para: {
   xpath: '//p',

   get:   'html'
 }
}

Now when you use the para parameter in your template/snippet code, the “<p>Sample text.<img src=”image.jpg” alt=”” id=”image” /></p>” will be returned.

innerhtml

Use this special value to obtain string with internal HTML code of the current node.

Code on the desktop site page:

<html>
 <body>
   <p>Sample text. <img src="image.jpg" alt="" id="image" /></p>
 </body>
</html>

Defining action to get inner HTML in the parameters collection in Flamingo IDE:

{
 para: {
   xpath: '//p',

   get:   'innerhtml'
 }
}

Now when you use the para parameter in your template/snippet code, the “Sample text.<img src=”image.jpg” alt=”” id=”image” />” will be returned.

node

Use this special value to return DOM element of the current node. You can work with it as regular DOM object afterwards. In case of multiple nodes it returns only the first one. Code on the desktop site page:

<html>
 <body>
   <p>Sample text. <img src="image.jpg" alt="" id="image" /></p>
 </body>
</html>

Defining action to get node in the parameters collection in Flamingo IDE:

{
 para: {
   xpath: '//p',

   get:   'node'
 }
}

Now when you use the para parameter in your template/snippet code, the

[Element]

object will be returned.

Usage examples

Example 1:Getting HTML Content and Attributes

Shows how to get HTML content and attributes using array of definitions.