1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

trying to understand some codes in template

Discussion in 'XenForo Development Discussions' started by typostudy, Apr 26, 2013.

  1. typostudy

    typostudy Member

        {xen:phrase discussion_in_x_started_by_y_date_z,
            'forum=<a href="{xen:link forums, $forum}">{$forum.title}</a>',
            'name={xen:helper username, $thread}',
            'date=<a href="{xen:link threads, $thread}">{xen:datetime $thread.post_date, html}</a>'}
    Above code is taken from acp->appearance->templates, thread_view
    1. in \XenForo\Template\Compiler\Tag\Description.php,
    public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options)
    {xen:phrase... is $children, right? what does array $attributes and $options mean?

    2. Is $forum, $thread global/variable? that we can use in every template?

    3. for
    {xen:datetime $thread.post_date, html}
    , it shows:Apr 17, 2013.
    {xen:datetime $thread.post_date, plain}
    , it show: Apr 17, 2013 at 6:41 AM. why?

    4. The above code shows in the front end:
    Discussion in 'Main Forum' started by test2, Apr 17, 2013 at 6:41 AM
    But if i run
    {xen:helper dump,{xen:phrase discussion_in_x_started_by_y_date_z...
    it shows in the front end:
    Discussion in '<a href="forums/main-forum.2/">Main Forum....
    so how did the system get rid of the hyperlinks?
  2. Jeremy

    Jeremy Well-Known Member

    2. No.
    3. That's odd...
  3. Uniphix

    Uniphix Active Member

    1. The <xen:description> at this case does not use any attributes, but there are other tags that do, for example <xen:if> has several types of attributes that can be used such as is="(CONDITION)" or hascontent="true" which actually requires <xen:contentcheck> tag within that <xen:if> tag.

    2. As King says no they are not global, but $visitor, $xenOptions, $xenCache, $debugMode, $visitorLanguage are all global and can be used in every container template as well normal default templates. Take a look inXenForo_Dependencies_Abstract::preRenderView function in library/XenForo/Dependencies/Abstract.php, the Public.php in that same path would also be useful for the front-end. The back-end is the Admin.php. In the public side (FrontEnd) there are other default variables such as $visitorStyle, $userFieldsInfo, Take a look in the inXenForo_Dependencies_Public::preRenderView

    3. To understand how {xen:datetime} works take a look at the function DateTime.php in XenForo_Template_Compiler_Function_DateTime (library/XenForo/Template/Compiler/Function/DateTime.php)

    WHen you see <xen:description> this refers to the Tag folder of the Template/Compiler/Tag directory, when you see {xen:datetime} this references to the Template/Compiler/Function directory.

    In the Function for DateTime.php

    * Class to handle compiling template function calls for "date", "time", and "datetime".
    * A formatted date or time will be output based on the timestamp in the first argument
    * and the browsing user's language.
    * An optional format override can be passed as the second argument. If provided,
    * this argument should be a named format.
    * @package XenForo_Template
    class XenForo_Template_Compiler_Function_DateTime implements XenForo_Template_Compiler_Function_Interface
        * Compiles the function call.
        * @param XenForo_Template_Compiler The invoking compiler
        * @param string                Name of the function called
        * @param array                  Arguments to the function (should have at least 1)
        * @param array                  Compilation options
        * @return string
    public function compile(XenForo_Template_Compiler $compiler$function, array $arguments, array $options)
    $argc count($arguments);
            if (
    $argc != && $argc != 2)
            if (empty(
    $arguments[1] = '';
            switch (
    $phpFunction $function;
    $phpFunction 'datetime';
    'XenForo_Template_Helper_Core::' $phpFunction
    '(' $compiler->compileAndCombineSegments($arguments[0], array_merge($options, array('varEscape' => false))) . ', '
    $compiler->compileAndCombineSegments($arguments[1], array_merge($options, array('varEscape' => false))) . ')';
    Is reference to XenForo_Template_Helper_Core::datetime($date, 'plain'); is what it ends up being if you take a look in library/XenForo/Template/Helper/Core.php

    search for

    public static function dateTime($timestamp$format null)

    in Core.php

    as I am looking it apparently means that it will still call this method even if it case insensitive. What happens is the format is "plain" that means it gets passed to

    return XenForo_Locale::dateTime($timestamp$formatself::$_language);
    Which is located in library/XenForo/Locale.php

    Using "plain" makes it use the default:

    $dateTimeFormat $language['date_format'] . '|' $language['time_format'];
    $formatPhrase 'date_x_at_time_y';
    Which in the format Phrase date_x_at_time_y if you look it up it will be...

    {date} at {time}
    when using "html" it shows

    return self::callHelper('datetimehtml', array($timestamp));
    Which eventually calls the helper

        * Returns an <abbr> tag with a date suitable for Javascript refreshing
        * @param integer $timestamp
        * @param array $attributes
        * @return string <abbr class="DateTime" data-unixtime="$timestamp"...
    public static function helperDateTimeHtml($timestamp$attributes = array())
    In there you can see how it is outputted which is in the end becomes

    $tag 'span';
    $data ' title="' $time['string'] . '"'// empty this to remove tooltip from non-relative dates
    $value $time['date'];
    and outputs as

    return "<{$tag} class=\"DateTime{$class}\"{$attribs}{$data}>{$value}</{$tag}>";
    Hope this helps!
    Pereira, arms and Brogan like this.
  4. typostudy

    typostudy Member

    Great .Thanks.

Share This Page