Jump to content


* * * * -
Photo

Parse Tags


You may have noticed when editing templates tags which look like this:
 
{parse var="foo" var2="bar"}
These are special "parse tags". There are many different types you can use. This guide is going to explain all of the types of parse tags available.


addtohead
{parse addtohead="file.js" type="javascript"}
This tag can add javascript, CSS or raw data to the head of a page.
The "type" attribute should be either "javascript", "inlinecss", "importcss" or "raw".


block
{parse block="key"}
This tag will display a block created in IP.Content.


date
{parse date="1254416063" format="long" relative="false"}
This tag will display a date in human-readable format from a timestamp.
The "date" attribute should be a unix timestamp.
The "format" attribute should be either "LONG", "SHORT", "SHORT2", "JOINED", "TINY" and determines the format (i.e. "LONG" will display the full date, including day of the week and full month name, while "SHORT2" will just display the date).  Be aware that administrators can modify these formats via ACP settings under Settings -> Advanced tab -> Date, Time and Number Formats, so while "SHORT2" may display just the date by default, this may not always be the case in the event the administrator changes the corresponding setting.  Dates and times are locale-aware.
The "relative" attribute should either be "true" or "false" - if "true", the appropriate settings are enabled, and it was a certain amount of time ago it may return something like "10 minutes ago" instead of an actual time.


expression
{parse expression="intval($data)"}
This tag takes a PHP expression and returns the result. Useful for using intval or str_replace with.


format_number
{parse format_number="123456"}
This tag formats a number as appropriate to the locale settings for the user's language. For example, it will convert 1000000 into 1,000,000 if the user's language choice is English.


include
{parse include="file_location.html"}
This will retrieve the contents of the file specified and insert it into the template.
Useful if you have a html header or other content outside of IP.Board that you want to include.


js_module
{parse js_module="name_of_module"}
This will get a javascript module. For example, use {parse js_module="editor"} to get the javascript required for the editor.
This is equivalent to $this->registry->getClass('output')->addJSModule('name_of_module');.


replacement
{parse replacement="a_post"}
This will return the image replacement variable for the user's skin choice. This is usually used to display images. You can edit image replacement variables for a skin by selecting "Manage Replacements" for the dropdown menu for the skin under the Look & Feel tab in the Admin CP.


resize_image
<img src='image.png' {parse resize_image="image.png" maxwidth="100" maxheight="100"} />
This will resize an image to the specified dimensions.
As shown in the example, it should be used in the image tag, as it will generate attributes for it.


striping
{parse striping="someKey" classes="row1, row2"}
{parse striping="someKey"}
This is used to use "stripey" rows. For example, if you have a table and want alternate rows to display slightly different colours.
Normally, you would start off by initiating the striping by using {parse striping=&quot;help&quot; classes=&quot;row1, row2&quot;} (where "row1" and "row2" are the CSS classes you wish to use) and then within your foreach loop, you would use a parse tag with the same key to return the class. For example:

{parse striping="example" classes="row1,row2"}

<foreach loop="$rows as $row">

	<div class='{parse striping="example"}'>

		Example

	</div>

</foreach>


template
{parse template="myTemplate" group="global" params="$data, $moreData"}
This can be used to display a template within another template.
The "template" paramater should be the name of the template bit you wish to call.
The "group" parameter should be what group it is in (e.g. "global", "topic", "forum", "ucp", etc).
The "params" parameter should be the variables to pass to it.


url
{parse url="this=that" base="public"}
This is used to display a link - it takes into account friendly URLs if enabled. You should use this tag to display any URL.
The "url" parameter should usually be whatever comes after index.php? - so to display a link to a user's profile you would use {parse url=&quot;showuser=X&quot;]}
The "base" parameter defines what to use as the base URL (i.e. what the "url" parameter will be added on to) - you can use "public", "admin", "publicWithApp", "public_dir", "img_url", "avatars", "emoticons", "mime" or "upload".
You can also use an "seotitle" parameter which will be used in friendly URLs - for example for a link to a user's profile you would display the members_seo_name value for the member.
You can also use a "template" parameter to provide the SEO template for friendly URLs, for example "showuser", "showtopic", etc. If none is passed but SEO is enabled, IPB will search all templates for a match
You can also define "httpauth" as "true" which will add the HTTP authentication information (as defined by setting in the Admin CP) to the URL.


variable
{parse variable="testKey" default="foo" oncondition="$data == \'new\'" value="bar"}
This will set a variable in the template.
The "variable" parameter should be the variable name.
The "oncondition" parameter should be the condition (in PHP code) that the variable will be set on.
The "value" parameter should be the value to set.
  • Haku2, bonesoul, Sandakelumô and 4 others like this



0 Comments


Developer Docs · Error Codes