Template inheritance

  • Hello,

    I would need a child template to fill a block in a parent template.

    This thing in smarty is possible with tag block, but when I try to use this tag on woltlab an error is returned.

    Is there a possibility of using something like this?


    Thanks for the future reply.


    EDIT: move this thread on Creating Styles

  • Hello,


    You want to include another template in a template, right? To which application does the "parent" template belong?

    Alexander Ebert
    Senior Developer WoltLab® GmbH

  • What I would like to do is move a part of the code of certain templates in the header.tpl to do this in many template engines you can create blocks in the fathers templates (in my case header.tpl) and fill them in the template that use the parent.

    Like block in smarty.


    Or component in blade

  • Hello,


    You can use the include tag to accomplish this:


    Code
    {include file='yourAwesomeTemplate'}


    You can create own templates through the admin panel, just pick a sufficiently unique name and make sure to not go too crazy with the filename.

    Alexander Ebert
    Senior Developer WoltLab® GmbH

  • Is not the same thing.

    If I am in the articles page, I should show the title of the article.


    If I'm on the user profile page it should show me the photo of the user with the cover.


    If I am on the personal blog page you should show me more information.


    I would need to be able to dynamically include data that are present in the corresponding templates: article, user, blog.

    Without going into conflict because maybe in user we have a user object with certain parameters that in blog for example does not have.


    For example. In the user object of the template user. The method for calling up the cover image is present.


    But the user object of the blog template does not have this method and rightly gives me errors.


    Is not there a way to use a component similar to that of a smarty or blade?


    Or still find a way to load components in pageHeader based on the template we are loading?


    For example, saying include your AwesomeTemplate only if you're on the articles page?



    Thanks Alexander Ebert :)

  • Hello,


    You can query the currently active main template and decide if you need to do anything:


    Code: yourAwesomeTemplate.tpl
    {if $templateNameApplication === 'wcf' && $templateName === 'user'}
        {* User Profile *}
    {elseif $templateNameApplication === 'blog' && $templateName === 'entry'}
        {* Blog Entry *}
    {/if}

    Alexander Ebert
    Senior Developer WoltLab® GmbH