Developer forum

Forum » Templates » Includes in Razor

Includes in Razor

Dmitrij Jazel
Reply

Hi everyone,

Wanted to ask, how do I make includes in Razor?

http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Include([Path]).aspx


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

You have to use @Include just as in HTML templates, i.e.

<!--@Include(somefile.html)-->

@if (GetInteger("counter") > 0) { ... }

We may introduce a more Razor-like syntax in the future, but for now you have to use @Include as shown above and described in the documentation.

Best regards,
Mikkel
 

Votes for this answer: 1
 
Dmitrij Jazel
Reply

Hej Mikkel,

Looking forward to see some more Razor tricks!!! :-)))

 

But please correct me if I am wrong, but Razor is unable to read ANY of dynamicweb html format tags. This means 

<!--@Include(somefile.html)-->

 

cannot be used at all.

 

not sure why I would have to use this than:

<!--@Include(somefile.html)-->
@if (GetInteger("counter") > 0) { ... }

I just tried to use the example you wrote here - and razor complains as expected.

is it some kind of "temporary work around"?

 

And than lastly you mentioned some kind of documentation.

Can I please have a link to that one? :-)

Thanks allot in advance :-)))

 

Regards,

Dmitrij

 
Mikkel Ricky
Reply

You can use @Include in Razor templates just as you can in HTML templates, i.e. <!--@Include(somefile.html)--> will work just as it has always worked and will include the file "somefile.html" (if it exists).

The documentation I'm referring to is the documentation that you referred to in your initial post.

Best regards,
Mikkel

 

 
Dmitrij Jazel
Reply

Ahh, thanks for help Mikkel,

Apparently it works. I had some other problem in my razor I can see. So it works now, thanks allot for help! :-)

//Dmitrij

 

 
Mikkel Toustrup Olsen
Reply

Hey Mikkel,

I was thinking of something.

I have an index.html file that includes several files - 3-4, all html files for now. Does DW accept that these included files have their own contentplaceholders.

E.g.

Index.html has 2 CTPH

 Index.html includes somefile.html

somefile.html have 1 contentplaceholder (class="dwcontent")

I see the contentplaceholder on my page that uses index.html as layout however I get some weird layout when editing stuff in the somefile.html content afterwards. I use the item functionality in the included file and in that razor as well

/MTO

 
Dmitrij Jazel
Reply

Hej MTO,

Can I ask you why you have somefiles.html inside index.html?

Do you want your index.html to be as "master page" so that each other file that you include in the index, could share the layout defined in index for all of them?

/Dmitrij

 
Mikkel Toustrup Olsen
Reply

Basically it was the way the design was structured from our frontend department. I just thought it could be an easier way to implement the design by keeping this structure. However, I think the best practice is to move the included .html files' markup into the index.html and create the contentplaceholders from there :-)

/MTO

 

You must be logged in to post in the forum