Developer forum

Forum » Feature requests » Custom variables for templates

Custom variables for templates

Søren Kottal-Nielsen
Reply
 With the addition of the tag @ParagraphContainer, it is now possible to create very versatile paragraph templates. Here is an idea to extend the versatility.

I.e. I have made this template, to show an image, in a width relative to the paragraph container.
<!--@If Defined(ParagraphImageClean)-->
	<img src="/admin/public/getimage.aspx?Image=<!--@ParagraphImageClean-->&Width=<!--@If(ParagraphContainer='billede')-->330<!--@EndIf--><!--@If(ParagraphContainer='mobilbillede')-->290<!--@EndIf-->&Height=<!--@If(ParagraphContainer='billede')-->320<!--@EndIf--><!--@If(ParagraphContainer='mobilbillede')-->280<!--@EndIf-->" width="<!--@If(ParagraphContainer='billede')-->330<!--@EndIf--><!--@If(ParagraphContainer='mobilbillede')-->290<!--@EndIf-->" height="<!--@If(ParagraphContainer='billede')-->320<!--@EndIf--><!--@If(ParagraphContainer='mobilbillede')-->280<!--@EndIf-->" <!--@If Defined(ParagraphImageLinkAlt)-->alt="<!--@ParagraphImageLinkAlt-->">
<!--@EndIf(ParagraphImageClean)-->

Notice the extremely long and clutterede <img>-tag.

Now, if you had some kind of ability to define your own variables in a template, this could be done much better. Like this:

<!--@If Defined(ParagraphImageClean)-->

	<!--@If(ParagraphContainer='billede')-->
		<!--@Var:myWidth=330-->
		<!--@Var:myHeight=320-->
	<!--@EndIf-->
	
	<!--@If(ParagraphContainer='mobilbillede')-->
		<!--@Var:myWidth=290-->
		<!--@Var:myHeight=280-->
	<!--@EndIf-->
	
	<img src="/admin/public/getimage.aspx?Image=<!--@ParagraphImageClean-->&Width=<!--@Var:myWidth-->&Height=<!--@Var:myHeight-->" width="<!--@Var:myWidth-->" height="<!--@Var:myHeight-->" <!--@If Defined(ParagraphImageLinkAlt)-->alt="<!--@ParagraphImageLinkAlt-->">
	
<!--@EndIf(ParagraphImageClean)-->
This is a very simple example, but I hope you get the idea.

Replies

 
Nicolai Høeg Pedersen
Reply
Hi Søren

Thank you for the idea. I like it - and will give it some more thoughts and make a test implementation to see how it could work.

Also brewing on making it possible to do .NET extenders that turns into functions: @func:somemethod(mytag)

 
David Matheson
Reply

Hi Søren,

I like your idea too, however your original code could have been simplified to:

 

<!--@If(ParagraphContainer='billede')-->
<img src="/admin/public/getimage.aspx?Image=<!--@ParagraphImageClean-->&width=330&height=320” width="330" height=320" />
<!--@EndIf-->    
<!--@If(ParagraphContainer='mobilbillede')-->
<img src="/admin/public/getimage.aspx?Image=<!--@ParagraphImageClean-->&width=290&height=280” width="290" height=280" />
<!--@EndIf-->
I've not added the alt tag here, but only so that the code is on one line in the forum : -)