diff options
| author | Simon Wisselink <wisskid@users.noreply.github.com> | 2021-12-03 11:59:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-03 11:59:22 +0100 |
| commit | 428a701b1871b02078a663d51a9a6555195743b3 (patch) | |
| tree | 51a76b654fb742dd9ea1ee6595baa27f113bc7ca /docs/designers/language-builtin-functions/language-function-capture.md | |
| parent | baebd59bb4da9fca89da382811b38c8313949c49 (diff) | |
| download | smarty-428a701b1871b02078a663d51a9a6555195743b3.tar.gz smarty-428a701b1871b02078a663d51a9a6555195743b3.tar.bz2 smarty-428a701b1871b02078a663d51a9a6555195743b3.zip | |
Feature/add docs (#689)
* Add converted docs repo
* Set theme jekyll-theme-minimal
* Removed BC docs, added TOC
* Added TOCs, rewrote most important links in documentation. Linked README to new Github Pages site
* some link fixes
Diffstat (limited to 'docs/designers/language-builtin-functions/language-function-capture.md')
| -rw-r--r-- | docs/designers/language-builtin-functions/language-function-capture.md | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/docs/designers/language-builtin-functions/language-function-capture.md b/docs/designers/language-builtin-functions/language-function-capture.md new file mode 100644 index 00000000..9121b287 --- /dev/null +++ b/docs/designers/language-builtin-functions/language-function-capture.md @@ -0,0 +1,82 @@ +{capture} {#language.function.capture} +========= + +`{capture}` is used to collect the output of the template between the +tags into a variable instead of displaying it. Any content between +`{capture name='foo'}` and `{/capture}` is collected into the variable +specified in the `name` attribute. + +The captured content can be used in the template from the variable +[`$smarty.capture.foo`](#language.variables.smarty.capture) where "foo" +is the value passed in the `name` attribute. If you do not supply the +`name` attribute, then "default" will be used as the name ie +`$smarty.capture.default`. + +`{capture}'s` can be nested. + +**Attributes:** + + Attribute Name Type Required Default Description + ---------------- -------- ---------- --------- ---------------------------------------------------------------------- + name string Yes *n/a* The name of the captured block + assign string No *n/a* The variable name where to assign the captured output to + append string No *n/a* The name of an array variable where to append the captured output to + +**Option Flags:** + + Name Description + --------- ----------------------------------------- + nocache Disables caching of this captured block + +> **Note** +> +> Be careful when capturing [`{insert}`](#language.function.insert) +> output. If you have [`$caching`](#caching) enabled and you have +> [`{insert}`](#language.function.insert) commands that you expect to +> run within cached content, do not capture this content. + + + {* we don't want to print a div tag unless content is displayed *} + {capture name="banner"} + {capture "banner"} {* short-hand *} + {include file="get_banner.tpl"} + {/capture} + + {if $smarty.capture.banner ne ""} + <div id="banner">{$smarty.capture.banner}</div> + {/if} + + + +This example demonstrates the capture function. + + + {capture name=some_content assign=popText} + {capture some_content assign=popText} {* short-hand *} + The server is {$my_server_name|upper} at {$my_server_addr}<br> + Your ip is {$my_ip}. + {/capture} + <a href="#">{$popText}</a> + + + +This example also demonstrates how multiple calls of capture can be used +to create an array with captured content. + + + {capture append="foo"}hello{/capture}I say just {capture append="foo"}world{/capture} + {foreach $foo as $text}{$text} {/foreach} + + + +The above example will output: + + + I say just hello world + + + +See also [`$smarty.capture`](#language.variables.smarty.capture), +[`{eval}`](#language.function.eval), +[`{fetch}`](#language.function.fetch), [`fetch()`](#api.fetch) and +[`{assign}`](#language.function.assign). |
