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

Equivalent of vBulletin's <if condition="THIS_SCRIPT != 'index'"> ?

Discussion in 'XenForo Development Discussions' started by dutchbb, Oct 18, 2010.

  1. dutchbb

    dutchbb Well-Known Member

    This allowed to show things on all pages except 'forumhome' in vB. Any idea what the equivalent is in XenForo?
    fattony69 likes this.
  2. Kier

    Kier XenForo Developer Staff Member

    The concept of THIS_SCRIPT from vBulletin doesn't really work in XenForo as the mechanism by which a page us built is so drastically different. However, Mike and I are investigating ways to expose some data from the controller and view layers that will hopefully give you tools to achieve what you want.
    Darkimmortal, RickM, Forsaken and 3 others like this.
  3. Vladislav Rastrusny

    Vladislav Rastrusny Active Member

    I think, we can currently examine controller class name to have some idea about where our content is going to be displayed.
  4. dutchbb

    dutchbb Well-Known Member

    Ok tnx. Another one we use is <if condition="in_array($GLOBALS[forumid], array(25,118,120,121,126,139,140))">

    I assume the same differences apply?
  5. Kier

    Kier XenForo Developer Staff Member

    Our template syntax for conditionals currently only supports simple equality checks, but we plan to extend it in the near future.
    Miko likes this.
  6. Miko

    Miko Well-Known Member

    Hi Kier, hope you can really add this to the template system, really missing this feature :)

    I have tried every possible combinations i can think of with AND, OR && ", ', { and more.... like for example:

    <xen:if is="'{$forum.node_id} == 8' AND '{$forum.node_id} == 2'">

    <xen:if is="'{$forum.node_id} == 8' &&  '{$forum.node_id} == 2'">
    Are not giving me any errors but also not working :(
  7. Kier

    Kier XenForo Developer Staff Member

    I think you need OR, not AND. The logic you posted there can never evaluate to true - how can the node_id ever be 8 AND 2?

    Additionally, you don't need to individually quote each clause, that would turn the checks into strings instead of logic.

    Try this instead:
    <xen:if is="{$forum.node_id} == 8 OR {$forum.node_id} == 2">
    Darkimmortal and Miko like this.
  8. Miko

    Miko Well-Known Member

    I did try OR but with the extra quotes :(

    Without the quotes is working perfectly , thank you Kier!

    Now I can go to sleep dreaming of beta two and you adding arrays in templates conditionals
  9. Floris

    Floris Guest

    It's RC1, is it possible yet?
    In another thread we want to say remove a block in the header from the register page. Checking against 'account' / 'profile' / 'login' / 'register' and a few others, quite handy.

    Hope to hear soon :)
  10. Laric

    Laric Active Member

    hmm if the route was visible I guess you could use that? Don't know if that is visible but that would definetly be a start.
  11. digitalpoint

    digitalpoint Well-Known Member

    Depending on how complicated you were willing to get, you could create an addon that does something based on:

    $fc->route()->getControllerName() != 'XenForo_ControllerPublic_Index'
    Floris likes this.
  12. Kier

    Kier XenForo Developer Staff Member

    I think we already expose the controller name to the template, but I'd have to double check that.
    Adshi and (deleted member) like this.
  13. Kier

    Kier XenForo Developer Staff Member

    Aah yes, there we go. This is from XenForo_Dependencies_Abstract::preRenderView():
    if ($controllerResponse)
    $this->_defaultTemplateParams['controllerName']   = $controllerResponse->controllerName;
    $this->_defaultTemplateParams['controllerAction'] = $controllerResponse->controllerAction;
    $this->_defaultTemplateParams['viewName']         = $controllerResponse->viewName;
    Therefore, you can access {$controllerName}, {$controllerAction} and {$viewName} from within templates and have just as much, if not more control than was ever possible using THIS_SCRIPT :)
    Liam W, Luke F, Arik and 2 others like this.
  14. Floris

    Floris Guest

    is so

    :D Thanks Kier for double checking. *runs to update templates and css*
  15. Floris

    Floris Guest

    page_container template:

    <p class="importantMessage">
    	controllerName: {$controllerName}, controllerAction: {$controllerAction} and viewName: {$viewName}.

    Attached Files:

    CyberAP, Dan, Miko and 1 other person like this.
  16. dutchbb

    dutchbb Well-Known Member

    So what's the code for showing for example an ad only in forum ID 1 ? Or is that still not possible? The THIS_SCRIPT alternative isn't entirely clear to me either?
  17. Kier

    Kier XenForo Developer Staff Member

    If you want to show an ad only in forum id 1, use this:

    <xen:if is="{$forum.node_id} == 1"><!-- ad code here --></xen:if>

    If you want to show something only on thread display pages, you could use this in vBulletin:

    <if condition="THIS_SCRIPT == 'showthread'"><!-- your stuff here --></if>

    Or this in XenForo:

    <xen:if is="{$controllerName} == 'XenForo_ControllerPublic_Thread' AND {$controllerAction} == 'index'"><!-- your stuff here --></xen:if>
  18. Floris

    Floris Guest

    kier ... </xen> should probably be </xen:if>
  19. Kier

    Kier XenForo Developer Staff Member

    Oops, fixed.
  20. dutchbb

    dutchbb Well-Known Member

    This one doesn't seem to be working on my test forums.

Share This Page