RM 2.2 Insert template on resource page

Andy.N

Well-known member
I would like to see how I can use conditional to insert template X on resource X, template Y on resource Y, etc.
And I would like to insert template X into this location. This part I figured out where to put them in xfrm_resource_wrapper_macros

Now I need to find a way to extract the id of the resource being display and insert a custom template in that position.

Screenshot 2023-03-19 at 1.35.57 AM.webp
 
Last edited:
Solution
This is the syntax to include a template with the name of the resource ID: <xf:include template="{$resource.resource_id}" /> .

The templates would then simply be numbered to match the ID.
Basically, I'd like to add template that is the same as the id of the resource being added.
Something like
Code:
<xf:include template="$resource.resource_id">
@Brogan can you help with this?
 
Here is one that @Chris D shows before which is simple. I can make 20 if statements for 20 resources but I think it would be more elegant to have a solution that use a loop statement to do that.
 
How the templates will be generated? If you have 100 resources, you will need 100 different templates?
What do you want to achieve exactly?
Oh, sorry I didn't explain clearly.
I will create the templates manually and name them according to the resource id. So I will create templates that each will have different content, tailored for each resource.
I just need a way to call them automatically.
 
Interesting.
So we must combine the syntax of condition with that of loop, I'm curious for a doable answer.

Loops in XF are like this:
HTML:
<xf:set var="$names" value="{{ ['Patrick', 'Theresa', 'Kimball', 'Wayne', 'Grace'] }}" />

<xf:foreach loop="$names" key="$key" value="$name" i="$i">
    <p>Hello there, {$name}. This is name number {$i}. Array key of this element: {$key}</p>
</xf:foreach>

For this result:
Code:
Hello there, Patrick. This is name number 1.
Hello there, Theresa. This is name number 2.
Hello there, Kimball. This is name number 3.
Hello there, Wayne. This is name number 4.
Hello there, Grace. This is name number 5.

I don't know where to start, I hope you get a positive answer.
 
Why do you need a custom template for each resource?
How are you generating the custom templates?
What are you trying to do?
Yes sir. Thank you for your help.
My resources are a bunch of different universities. I want to insert graphs showing admission data, employments over the years. It will use highcharts graphs with javascripts and put them into the templates. Call it template 1 to be used for resource id 1.
I will create these templates manually from back end and paste the code to generate graphs there.
I hope it is clear what I want to do.
 
Personally I would do something like this, to ensure there is no chance of a conflict.

HTML:
<xf:include template="andyn_resource_{$resource.resource_id}" />

Then the template names would be e.g. andyn_resource_1, andyn_resource_2 , etc.
 
Back
Top Bottom