I just stumbled upon the concept of buffering output using the capture tag (http://www.couchcms.com/docs/tags-refer ... pture.html) in the contact form tutorial.
If I understand this correctly, we store the content within the capture tags in a variable which we then echo to the view:
The question is why would we do that?
The only logical use case I see (in the context of the contact form tutorial) is that we want to make a local variable from a specific template available in the global context; e.g. show social media links at another place without creating a new variable in another view (footer, header etc):
- Is this the intended use case of the capture tag?
- Is it safe to set global variables in this way?
- What is the recommended way to work with variables that should appear at a global context (e.g. contact information, social media links etc)?
I would appreciate your clarification.
If I understand this correctly, we store the content within the capture tags in a variable which we then echo to the view:
- Code: Select all
<cms:capture into='my_variable' scope='global'>
..everything executed here will get stored in variable 'my_variable' at the requested scope..
</cms:capture>
</cms:show my_variable />
The question is why would we do that?
The only logical use case I see (in the context of the contact form tutorial) is that we want to make a local variable from a specific template available in the global context; e.g. show social media links at another place without creating a new variable in another view (footer, header etc):
- Code: Select all
<cms:set has_profile='1' 'global' />
<cms:if has_profile >
<cms:show profiles_output />
</cms:if>
- Is this the intended use case of the capture tag?
- Is it safe to set global variables in this way?
- What is the recommended way to work with variables that should appear at a global context (e.g. contact information, social media links etc)?
I would appreciate your clarification.