Developer forum

Forum » CMS - Standard features » Page items
Thomas Schroll
Reply

Hi

I'm setting up new forms used on landingpages. I need to place different snippets of text in the form. I prefer to place all the text at the right place instead of manipulating the position with css. The site is multi lingual which mean that I can't just use multiple templates (there would be to many). I can't use the submit label in the forms module because I need to insert event based tracking codes in the submit tag.

As I see it, it leaves me with creating page item fields. My problem is that I can't figure out how to insert page item fields in the module template like area item fields. I previously used snippets in the page template but with many snippets of text (4 or more) I would like to insert the page item fields directly in the (forms) module template.

Does anybody know if that is possible and how I can do that?

Regards Thomas


Replies

 
Nicolai Høeg Pedersen
Reply

If you are using an item type to exten the page properties, you have a tag called Item.Page.fieldname that can be used all over. Is that what you mean?

Nicolai

 
Thomas Schroll
Reply

Hi Nicolai

Yes I'm extending the page properties.

I have tried @GetString("Item.Page.FormSubmitLabel") in the form template, but dw doesn't render anything?

Regards Thomas

 
Nicolai Høeg Pedersen
Reply

Hi Thomas

Is the value available in the layout template on that page?

Nicolai

 
Thomas Schroll
Reply

Hi Nicolai

Yes, it is available in the page layout template.

Regards Thomas

 
Nicolai Høeg Pedersen
Reply

Ok, the tag is not available in the forms template context.

But the form is being rendered on a page, and therefore you have a pageview context. And since your template is Razor, you can simply get the value from there:

@Dynamicweb.Frontend.PageView.Current.Page.PropertyItem.Item("FormSubmitLabel")

BR Nicolai

 
Thomas Schroll
Reply

Hi Nicolai

Thanks, but I get an error: 

'Dynamicweb.Frontend.PageView.Current()' is a 'method', which is not valid in the given context

What am I doing wrong?

Regards Thomas

 
Mikkel Ricky
Reply

You have to write

@Dynamicweb.Frontend.PageView.Current().Page.PropertyItem.Item("FormSubmitLabel")

i.e. with () after Current. However, in a Razor template you can also just write

@Pageview.Page.PropertyItem.Item("FormSubmitLabel")

which is shorter (@Pageview is the same object as @Dynamicweb.Frontend.PageView.Current()).

Best regards,
Mikkel

 
Thomas Schroll
Reply

Hi Mikkel

I think I've tried every possible combination. If I insert

                <p>@GetString("Item.Page.FormSubmitLabel")</p>
                <p>@Dynamicweb.Frontend.PageView.Current().Page.PropertyItem.Item("FormSubmitLabel")</p>

I get the error:

'Dynamicweb.Content.Items.Item' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'Dynamicweb.Content.Items.Item' could be found (are you missing a using directive or an assembly reference?)

If I comment out the second line, it's working fine.

If I insert

                 <p>@Pageview.Page.PropertyItem.Item("FormSubmitLabel")</p>

I get the same error.

Regards Thomas

 

 

 
Nicolai Høeg Pedersen
Reply

Hi Thomas

It is because we mixed up VB examples with C# and you are using C#. .Item is a default property and is not needed in C#, and we use ("") which is VB syntax, [""] is C# syntax

@Pageview.Page.PropertyItem.Item("FormSubmitLabel") in VB is @Pageview.Page.PropertyItem["FormSubmitLabel"] in C#

Nicolai

 
Mikkel Ricky
Reply
This post has been marked as an answer

You have to write

@Pageview.Page.PropertyItem["FormSubmitLabel"]

and before doing that you shoul check that @Pageview.Page.PropertyItem is not null:

@if (Pageview.Page.PropertyItem != null) {
  @Pageview.Page.PropertyItem["FormSubmitLabel"]
}

You can get some help with using stuff like this in your Razor templates by using Visual Studio to edit your Razor templates. See https://github.com/dynamicweb/razor/wiki/Editing-Razor-templates for details.

Best regards,
Mikkel

 

Votes for this answer: 1
 
Thomas Schroll
Reply

Great. Now it's working. Thanks :)

Regards Thomas

 
Thomas Schroll
Reply

Hi Mikkel

Yes, but I haven't had the right setup (yet), but I will need to look into it.

Thanks for your help.

Regards Thomas

 

 
Mikkel Toustrup Olsen
Reply

Hi Mikkel,

Are you able to get item label from the Pageview object as well? I have tried several methods, however with no luck :(

Regards,

Mikkel TO

 

You must be logged in to post in the forum