Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Best Wedding Dresses Australia at AuBridalDresses.com

Find free files to download on allwhatyouwant.net

Advertisement

{block}

{block} is used to define a named area of template source for template inheritance. For details see section of Template Interitance.

The {block} template source area of a child template will replace the correponding areas in the parent template(s).

Optionally {block} areas of child and parent templates can be merged into each other. You can append or prepend the parent {block} content by using the append or prepend option flag with the childs {block} definition. With the {$smarty.block.parent} the {block} content of the parent template can be inserted at any location of the child {block} content. {$smarty.block.child} inserts the {block} content of the child template at any location of the parent {block}.

{blocks}'s can be nested.

Attributes:

Attribute Name Type Required Default Description
name string Yes n/a The name of the template source block

Option Flags (in child templates only):

Name Description
append The {block} content will be be appended to the content of the parent template {block}
prepend The {block} content will be prepended to the content of the parent template {block}
hide Ignore the block content if no child block of same name is existing.
nocache Disables caching of the {block} content

Example 7.15. Simple {block} example

parent.tpl


<html>
  <head>
    <title>{block name="title"}Default Title{/block}</title>
    <title>{block "title"}Default Title{/block}</title>  {* short-hand  *}
  </head>
</html>

  

child.tpl


{extends file="parent.tpl"} 
{block name="title"}
Page Title
{/block}

  

The result would look like


<html>
  <head>
    <title>Page Title</title>
  </head>
</html>


Example 7.16. Prepend {block} example

parent.tpl


<html>
  <head>
    <title>{block name="title"}Title - {/block}</title>
  </head>
</html>

  

child.tpl


{extends file="parent.tpl"} 
{block name="title" prepend}
Page Title
{/block}

  

The result would look like


<html>
  <head>
    <title>Title - Page Title</title>
  </head>
</html>


Example 7.17. Append {block} example

parent.tpl


<html>
  <head>
    <title>{block name="title"} is my title{/block}</title>
  </head>
</html>

  

child.tpl


{extends file="parent.tpl"} 
{block name="title" append}
Page Title
{/block}

  

The result would look like


<html>
  <head>
    <title>Page title is my titel</title>
  </head>
</html>


Example 7.18. {$smarty.block.child} example

parent.tpl


<html>
  <head>
    <title>{block name="title"}The {$smarty.block.child} was inserted here{/block}</title>
  </head>
</html>

  

child.tpl


{extends file="parent.tpl"} 
{block name="title"}
Child Title
{/block}

  

The result would look like


<html>
  <head>
    <title>The Child Title was inserted here</title>
  </head>
</html>


Example 7.19. {$smarty.block.parent} example

parent.tpl


<html>
  <head>
    <title>{block name="title"}Parent Title{/block}</title>
  </head>
</html>

  

child.tpl


{extends file="parent.tpl"} 
{block name="title"}
You will see now - {$smarty.block.parent} - here
{/block}

  

The result would look like


<html>
  <head>
    <title>You will see now - Parent Title - here</title>
  </head>
</html>


See also Template Inheritance, $smarty.block.parent, $smarty.block.child, and {extends}

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 11 plus 11? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
GoDaddy Coupon @buy-hosting.net
First Click Internet Marketing @fcinternetmarketing.com