Developer forum

Forum » Rapido » Custom website settings in Rapido

Custom website settings in Rapido

Søren Bremholm Jakobsen
Reply

Hi,

I have created two custom website settings (link to pages) in the custom website itemtype - how do I the render the content in the product template?

have tried different tage - ex. var freeShippingPage = Pageview.Area.Item["FreeShippingPage"];

But I have found the right tag yet. The systemname for the Item is FreeShippingPage.

 

The product template uses the RazorTemplateModel @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>


Replies

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
This post has been marked as an answer

Hi Søren

You are on the right path by using Pageview. As "Custom settings" is a shared item type, to get the value outside of the Master is not that simple. But it is possible. Here is one way to do it:

@{
      Dynamicweb.Content.Items.Item customSettings = Dynamicweb.Content.Items.Item.GetItemById("CustomSettings", Pageview.Area.Item["CustomSettings"].ToString());
      string freeShippingPage = customSettings["FreeShippingPage"];

}

Hope it works

 

Best regards
Karsten Thuen

Votes for this answer: 1
 
Søren Bremholm Jakobsen
Reply

Thanks for guiding me Karstensmiley,

just had to make some minor changes:

@{
                    Dynamicweb.Content.Items.Item customSettings = Dynamicweb.Content.Items.Item.GetItemById("CustomWebsiteSettings", Pageview.Area.Item["CustomSettings"].ToString());
                    string freeShippingPage = customSettings["FreeShippingPage"].ToString();
                    string exchangePolicyPage = customSettings["ExchangePolicyPage"].ToString();
                }

 
Thomas Jensen
Reply

Hi

In Rapido 3

I have tryed many combinations, to get content from the default custom field "CustomSetting" in to the default master template, not that I want to use that, but if I can get that to work I can properly also get my own to work, including Sørens code

@{
    Dynamicweb.Content.Items.Item customSettings = Dynamicweb.Content.Items.Item.GetItemById("CustomWebsiteSettings", Pageview.Area.Item["CustomSettings"].ToString());
    string CustomSettingsField = customSettings["CustomSettings"].ToString();
}

And all I get is "Object reference not set to an instance of an object."
What am I missing?

Regards Thomas

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Thomas,

 

Depending if you're using ViewModels or Templates you can use one of these options:

 

Model.Item.GetItem("CustomSettings").GetString("YOUR_CUSTOM_FIELD")

Or

Pageview.AreaSettings.GetItem("CustomSettings").GetString("YOUR_CUSTOM_FIELD")

 

Best Regards,

Nuno Aguiar

 
Lars Larsen
Lars Larsen
Reply

Hi

Have been struggeling getting a custom field from CustomSettings. Because Nuno's solution does not work on Rapido 3.3. Here this is the way to get custom website settings if you use Templates:

Pageview.AreaSettings.GetItem("Custom").GetItem("CustomSettings").GetString("YOUR_CUSTOM_FIELD")

If you're using ViewModels it must be (have not tried it!):

Model.Item.GetItem("Custom").GetItem("CustomSettings").GetString("YOUR_CUSTOM_FIELD")
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Lars,

If you are using the Model, you should use Model.Area.Item.GetItem("Custom")...

Adrian

 
Lars Larsen
Lars Larsen
Reply

Hi Adrian

Thanks Adrian. As I wrote I haven't tried it wink

 

You must be logged in to post in the forum