is there a way for me to use a functionality similar to what are called Global Variables in the Spark View Engine, but for Razor.
The point of it all lis to be able to define a variable in one section for the title and then being able to set or change the value of that variable later on in another section.
In Spark you would create the variable in a section kind of like this (incomplete code for example purposes):
I generally set 'global' items within a specific tab on the homepage node (such as title, telephone etc).
If they need to be overridden further down the tree, then you add the same element to that document type as well. Then you can call the property and make it recursive.
I personally, do not see the need to have global variables set in the templates.
Generally, as Richard states, you would set these on a node in the CMS and then reference them. That way the values can be edited in Umbraco.
However, you could create a static C# class that just contained static or constant properties and then reference these anywhere in your code (including views) if you really wanted.
namespace MyNameSpace
{
public static class MyConstants
{
public const string Title = "This is a title";
public const int SecretId = 1234;
// etc
}
}
Then in your view you'd just go:
The title is @MyConstants.Title
You can also create Partial classes for more complex reusable data.
how can i change the title value when its a const ?
i want to set the title value in a specific macro and i want the new value to be printed every ware i used before rendering dom
Global Variables in Razor View Engine
is there a way for me to use a functionality similar to what are called Global Variables in the Spark View Engine, but for Razor.
The point of it all lis to be able to define a variable in one section for the title and then being able to set or change the value of that variable later on in another section.
In Spark you would create the variable in a section kind of like this (incomplete code for example purposes):
And then you could set it in a different view or section or whatever:
How would I go about doing something like this in Razor or just solving a similar problem if I have the wrong approach ?
Hello
I generally set 'global' items within a specific tab on the homepage node (such as title, telephone etc).
If they need to be overridden further down the tree, then you add the same element to that document type as well. Then you can call the property and make it recursive.
I personally, do not see the need to have global variables set in the templates.
Hello Richard
when i want to overwrite title i am not bring the value from document type can you explain more please ?
Generally, as Richard states, you would set these on a node in the CMS and then reference them. That way the values can be edited in Umbraco.
However, you could create a static C# class that just contained static or constant properties and then reference these anywhere in your code (including views) if you really wanted.
Then in your view you'd just go:
You can also create Partial classes for more complex reusable data.
Hi Dan
how can i change the title value when its a const ? i want to set the title value in a specific macro and i want the new value to be printed every ware i used before rendering dom
is working on a reply...