[Guide] XenForo Template Syntax

Status
Not open for further replies.

Hagai

OMG Member
Joined
Oct 9, 2010
Messages
207
The xenForo template Syntax guide
written by Hagai for xenFans


The xenForo template system is very unique.
This guide was written for you to get basic knowledge of the template syntax.
Lets start shall we?

Every xenForo template function starts with xen:.
For example: {xen:link}

  1. <xen:require />”
    this function as the following attributes: <type>=”<location>”.
    This function is the same function as “require_once(<location>);” in PHP.
    The type can be: css/js(in lowercase). And the <location> at CSS type is the CSS template name.
    Every require must end with “/>”.
  2. "<xen:include />”
    this function as the sane attributes of the require function.
    But, the her type can be only “template” and the location is the template name
    The big difference between require and include is that in include you can and may declare the template variable!
    For example:
    HTML:
      	<xen:include template=”myTemplate”><xen:set 	var=”$myTemplateVar”>myTemplateVarValue</xen:set>
      	</xen:include>
    Every <xen:include must end with “/>” or “></xen:include>”
  3. "<xen:set></xen:set>”
    The function is the function we use to declare a variable in a template.
    Her usage is: <xen:set var=”$<varname>”><varvalue></xen:set>.
    The Variable name must apply to the conditions of the php variable name.
    PHP:
      $$varname = not good!
      $_VarName 	= good :)
    Every “<xen:set>” must end with “</xen:set>”
  4. "<xen:if>{<xen:else />}</xen:if>”.
    The “<xen:else />” property is only optional.
    The “<xen:if>” syntax is:
    HTML:
      <xen:if <type>=”<condition>”>
      	true statments
      {
      <xen:else />
      	false statments
      }
      </xen:if>
    brackets mean optional code.
    The type can be: hasconent(I will explain later) and is.
    The usage of is:
    HTML:
      <xen:if 	is=”{$variable)”>
      the variable “variable” is 	exist
      <xen:else />
      The variable “variable 	doesn't exist
      </xen:if>
    you can get a condition of multipi check with “OR” and “AND” operators, To check a value of the variable we use “{$variable} <operator> '<value>'”, operator can be: ==, !=, <=, <. >=. >, <>. value can be numeric and string.
  5. "<xen:foreach></xen:foreach>”
    The “<xen:foreach>” is the equivalent of the foreach loop in PHP. Her attributes are:
    loop, and value. Loop is the similar as “$foo” in the php foreach and the value is the item in the php foreach. Example:
    HTML:
    <xen:foreach loop="$foo" 	value="$item">
    statment 	block
    </xen:foreach>
    is the same as
    PHP:
    foreach( $foo as $item ) {
    statment 	block
    }
  6. The variables in xF templates.
    In order to output the value of an variable we use
    HTML:
    {$<varname>}.
    If the variable is 	an 1-D array we use: [code=html]{$<arrayname>.<arrayitem>}
    in order to output the array item.
  7. Displaying phrases, in order to output an phrase we are using the
    HTML:
    {xen:phrase <phrasevarname>}
    the phrasevarname is the variable name of the phrase. For example:
    I've just created a phrase that is text is: “Hello World!” and is varname is “hello_world”, In order to output him I will use
    HTML:
    {xen:phrase hello_world}
    .
  8. "<xen:title></xen:title>”
    the “<xen:title>” function determins the “Ttitle” of the page. By saying title I mean:
    The thing is yellow marked is the “title” to set your own title you can use:
    HTML:
    <xen:title>My 	new title</xen:title>
  9. The security token. XF programers created an automaticly secuirity token to handle “CSRF” attacks. To use this “security token” in your template use the next expression:
    HTML:
    {$visitor.csrf_token_page}
    .
    If you are creating your own form you must add the next line to avoid errors:
    HTML:
    <input 	type="hidden" name="_xfToken" 	value="{$visitor.csrf_token_page}" />
I hope that everything is clear, if not your are always welcome to contact me in a conversation or in my profile page.
 

George G Halstead

OMG Member
Joined
Oct 24, 2010
Messages
436
Very nice, thanks for this. Just noticed there is no way to print a topic yet. I will read here as i go with my first theme try.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Very nice, thanks for this. Just noticed there is no way to print a topic yet. I will read here as i go with my first theme try.

Since XenForo is semantic html, printing it without css will basically be the print-version. I don't remember at this second if it has a print.css support - good suggestion if it hasn't.
 

dmnkhhn

OMG Member
Joined
Nov 1, 2010
Messages
16
If you would like to create a button that sits next to the breadcrumb (like the Post New Thread button), you can use:
PHP:
<xen:topctrl>
		<a href="{xen:link 'full:member', $user}" class="callToAction"><span>A cool button!</span></a>
</xen:topctrl>

It will automatically place the button at that location and it's already styled. :)
 

Attachments

  • Bildschirmfoto 2010-11-01 um 19.23.27.png
    Bildschirmfoto 2010-11-01 um 19.23.27.png
    26.4 KB · Views: 21

Hagai

OMG Member
Joined
Oct 9, 2010
Messages
207
Really nice!
i will add it while adding the XEN:LINK function as well.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Please create your own content instead of having others do the work and then just translate it to create a somewhat popular site ..

Personally I find it quite frustrating that I am constantly asked by everybody if they can just re-use and re-purpose the content that others create, rather than spend the time being innovating enough and create their own community.

On the other hand, I would love to work together. So feel free to translate it, publish it in 1 post here as a response. And on your community link to us if you still feel like it. I can't grant people permission to re-use our content.

Please note that this is nothing personal against you or your site. And that I am still thinking about a policy that helps us all to work together, and that people don't have to ask all the time. Hopefully we have something to announce in May. There are French, German, Spanish, Italian, Turkish XenForo site.

Until then, I hope people respect our position and share their contributions (such as a translation) within the official release thread here, rather than take the content to their own sites.
 

PoLiZe_imported

OMG Member
Joined
Apr 7, 2011
Messages
4
Ok, i aren't "very good" on XenForo, but i really like this guide, and in XenFacil (isn't my forum, i'm a translator) we haven't any guide of that.

I ask u because i dont like translate and post any article without permission.

Thank you.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,100
Ok, i aren't "very good" on XenForo, but i really like this guide, and in XenFacil (isn't my forum, i'm a translator) we haven't any guide of that.

I ask u because i dont like translate and post any article without permission.

Thank you.

I knew the name was familiar. xenfacil had redistributed my code without my permission. The user got banned for obvious reasons. They're blacklisted, and we will never grant permission again to translate our work or distribute it. That's the last thing I will say about it to avoid ruining this thread.
 
Status
Not open for further replies.
Top