Developer forum

Forum » Templates » Setting variable in Page template and Getting variable in Paragraph template

Setting variable in Page template and Getting variable in Paragraph template

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I've been trying to set a value in a Page template and then access the value in a Paragraph template.

 

I am setting the value as such:

Dynamicweb.Context.Current.Items.Add("MyValue", MyListVariable);

 

I tried with a simple string value, but for whatever reason the value the key is null in the Paragraph template.

Makes me wonder if the paragraph templates are generated before the page template. And if that's the case, how could I achieve this?

 

Best Regards,

Nuno Aguiar

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

The order of rendering is opposite. First everything that needs to go into a page is rendered, i.e. paragraphs, and  in the end the page is rendered using the content from the rendered parargraphs.

Your code is a possible to solution to a problem - can you describe your problem, then we might be able to help with a solution. What are you trying to achieve - what are you 'moving' from the page to the paragraph?

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Ah.... that explains it.

 

I am running some sql queries in the Themes Collection pages to figure out what themes are being used and in which areas/pages/paragraphs, in order to do some audits/cleanup. Because it's very "costly" in terms of performance and database calls, I only want to do it once, save the results in a List of objects and then for each paragraph (Theme) check against that list.

 

This was still a POC, hence the template approach; And I guess I can move my code to an assembly, although I wanted to see if the Swift team adopted it :P

 

I'm looking into this because it's easy for our customers to get a messy amount of themes and loose track of what themes are being used and where and how many times. This would allow them to figure out the 0 usages or the single-used ones and adopt another one for consistency.

I have the logic, sql queries and most of it worked out by now. I just need to access this list of objects on each theme.

 

I also thought in doing this in SQL, by running a procedure  (or a scheduled task) and populating a temp table and querying that temp table instead. Has it's pros and cons too.

 

Hope that makes sense. And if you have another way to do  it, I'd be happy to hear it.

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum