Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple custom variables on a template/layout


Go to End


2 Posts   1590 Views

Avatar
Fedorawearingpolarbear

Community Member, 3 Posts

9 March 2012 at 7:27am

I'm looking for the best but simplest way to have multiple custom variables on a page layout, the variable output would different depending on the page.

For example three variables; name, price, sku number. There are three products, each product needs those variables. However each of those variables output would be different depending on the product.

I've looked into template variables.

function MyCustomValue() {
    return "Hi, this is my site";
}

However it doesn't seem efficient since I would have to create a custom value for each page. A custom field box when creating a page in the admin panel would be prefered; in the product layout where ever $Price is placed it would output the value that was typed in the custom field, I imagine this is difficult to create. I have briefly looked into dataobjects, I can't seem to wrap my head around them. What is the best solution for what I want to do?

Avatar
Willr

Forum Moderator, 5523 Posts

12 March 2012 at 9:24pm

A custom field box when creating a page in the admin panel would be prefered

Adding fields to pages is easy. Make sure you've read the first 2 tutorials which cover adding fields to pages. If your products are already pages then you don't need DataObjects.