• 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'"> ?

Kier

XenForo Developer
Staff member
#2
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.
 

dutchbb

Well-known member
#4
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?
 

Kier

XenForo Developer
Staff member
#5
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?
Our template syntax for conditionals currently only supports simple equality checks, but we plan to extend it in the near future.
 

Miko

Well-known member
#6
Our template syntax for conditionals currently only supports simple equality checks, but we plan to extend it in the near future.
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:

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

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

Kier

XenForo Developer
Staff member
#7
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:
HTML:
<xen:if is="{$forum.node_id} == 8 OR {$forum.node_id} == 2">
 

Miko

Well-known member
#8
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:
HTML:
<xen:if is="{$forum.node_id} == 8 OR {$forum.node_id} == 2">
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
 
F

Floris

Guest
#9
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.
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 :)
 

Laric

Active member
#10
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.
 

digitalpoint

Well-known member
#11
Depending on how complicated you were willing to get, you could create an addon that does something based on:

Code:
$fc->route()->getControllerName() != 'XenForo_ControllerPublic_Index'
 

Kier

XenForo Developer
Staff member
#13
Aah yes, there we go. This is from XenForo_Dependencies_Abstract::preRenderView():
PHP:
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 :)
 
F

Floris

Guest
#15
page_container template:

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

Attachments

dutchbb

Well-known member
#16
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?
 

Kier

XenForo Developer
Staff member
#17
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?
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>