I add it on PAGE_CONTAINER template, is that okay?
This might or might not work, depending on where you want to access the param.
XenForo template engine works like this:
The template to be used is defined in the controller by code like
PHP:
return $this->view($viewClass, $viewTemplate, $viewParams);
The defined template
$viewTemplate
(which might be smth. like
thread_view
does get rendered and while it is being rendered, all sub-templates/macros do get included.
Afterwards, template
PAGE_CONTAINER
does get rendered which does get the HTML of the rendered template as variable
$content
.
While rendering
PAGE_CONTAINE
R, other templates (like the one for ad position
container_header
) do get included.
So if you define a page param right at the top of PAGE_CONTAINER you can use it in templates that are included by PAGE_CONTAINER; however you can't use it in templates like
thread_view
(and templates included by those templates) as those are rendered before rendering of
PAGE_CONTAINER
has started.
So for your specific question if depends on the ad location where you would to use the param:
- container_breadcrumb_top_above
- container_breadcrumb_top_below
- container_header
- container_sidenav_above
- container_sidenav_below
- container_content_above
- container_content_below
- container_sidebar_above
- container_sidebar_below
- container_breadcrumb_bottom_above
- container_breadcrumb_bottom_below
would work - others (eg. those within specific templates) would not.
A generic approach purely with templates that should always work:
Create a template
my_node_ids
Code:
<xf:page option="publicNodeIds" value="{{ [1, 2, 3] }}" />
<xf:page option="privateNodeIds" value="{{ [4, 5, 6] }}" />
<xf:page option="optionalNodeIds" value="{{ [7, 8, 9] }}" />
and include this everywhere you need your checks like
Code:
<xf:include template="my_node_ids" />
Afterwards you could use conditions like
Code:
<xf:if is="in_array($__globals.forum.node_id, page_param('publicNodeIds'))">
Though this isn't terribly efficient and kinda hacky, using an Add-on would be cleaner
You could also just use a configuration array in config.php
PHP:
$config['rdn_publicNodeIds'] = [1, 2, 3];
This could be accessed in any templates via
Code:
<xf:if is="in_array($__globals.forum.node_id, $xf.app.config.rdn_publicNodeIds)">