With Silverstripe templates, can I pass a variable from one include to another?
Within Order_ConfirmationEmail.ss <% include Order SendingEmail=true %>. Set $SendingEmail to true.
And in Order.ss pass $SendingEmail to another template via another include:
<% include Order_Content SendingEmail=$SendingEmail %>
Then use the variable $SendingEmail in Order_Content.ss:
<% if $SendingEmail %>We are sending an email <% end_if %>
Unfortunately, $SendingEmail does not have a value in Order_Content.ss (it does in Order.ss). Is this approach possible? Is there a better way. Thanks in advance.
It should. I'm not sure of all the ins and outs unfortunately, but so far as I know that is a thing (being able to pass any variable in scope). But there are a number of caveats you should probably be aware of. The biggest one being scope. If you're changing context at any point (and you have multiple layers so this is somewhat likely) you need to ensure the variable you're attempting to reference is in scope. Otherwise it will be blank, and thus report as such on any further reference to it. This is the most common problem when it comes to templates, so it always pays to double (triple) check.
Related
For example I want to use a nested helper like this:
{{#submission}}
{{field}}
{{/submission}}
But I want {{field}} in this case to be a different helper from the one above
{{#post}}
{{field}}
{{/post}}
and maybe even something else if used when not inside either of those (or perhaps just displaying data that passed, and not triggering a helper).
{{field}}
Is this possible, or do I have to make every helper unique?
I'm sorry but every helper has to be unique. If you want to use a different code then you have to do it programmatically by handling a parameter and switching your code depending on your parameter.
How does one go about adding Handlebars helpers to the scaffolt processing that comes with brunch? I'd like to do some more interesting conditional statements in my scaffolt templates but need to understand this process.
Oh, also, does anyone have any smart helpers that look at a name and deduce if the name indicates being singular or plural?
The best way, of course, is to convert the method to a property. But I can't do that here --
We have an API from someone else, and we've added an extension method to one of the objects. We need at the string this method returns in a data-binding situation (a GridView).
It doesn't seem that we can add an extension property (man, that would have been really nice...), so I have this method, and I want the cleanest way possible to render it in data-binding:
While I can do this with a property:
<%# Eval("MyProperty") %>
I have to do this with a method:
<%# ((MyClass)Container.DataItem).MyExtensionMethod() %>
This is how I've done it in the past, but is there a cleaner way than that? I can't change the class (it's not mine), and I can't add an extension property, so I'm stuck with this method.
I guess you could write your own method that took the Container object and the name of the method as a string, then used reflection to invoke the method. It'd look something like this in the end:
<%# Call(Container, "MyExtensionMethod") %>
I doubt you can get much cleaner than that, since Eval is a special case which is rewritten at compile-time.
If I have a control, within a FormView, that is bound using a <% #Bind(...)%> expression. At run time, is there any way of retrieving the name of the field the control is bound to.
To be clear, if the expression is <% #Bind("UserName") %>
I want to return the string "UserName".
after messing around extensively in debug, I found this to work
((System.Web.UI.WebControls.AutoGeneratedField)((System.Web.UI.WebControls.DataControlFieldCell)(e.Row.Cells[0])).ContainingField).SortExpression
In debug use shift+F9 to open the quick watch window pain and explore your Event Argument visually
I've been trying this a couple of different ways, but it's not working for some reason. Is it even possible?
Yes. Separate them in your declaration by semicolons.
If you are overriding GetVaryByCustomString() in the Global.asax.cs file, you can pass in a semicolon delimited list of values which you then need to parse.
There is one built-in value (Browser) which will be used if the attribute specified does not exist.
You can use multiple parameters by separating them by a semicolon, but you have to implement the logic of splitting them yourself. This means you can use any character as your separator, because you need to parse it yourself.
You probably overriding GetVaryByCustomString(HttpContext context, string custom) in your global.asax. The custom parameter will contain anything you pass using VaryByCustom, like this
<%# OutputCache Duration="86400" VaryByParam="none" VaryByCustom="custom1;custom2" %>
Extra note: base.GetVaryByCustomString doesn't implement any string splitting capabilities and will only do something when browser is passed as a value. Otherwise it will return null.