Developer forum

Forum » Templates » Global page content - Missing layout

Global page content - Missing layout

Jakob Westhausen
Reply

How come when I use <!--@Global:Page.Content([ID])--> or @RenderPageContent([ID]) only the paragraphs is outputtet and the page template mark-up is missing?

Screen_Shot_2014-12-09_at_08.49.40.png Screen_Shot_2014-12-09_at_08.50.01.png

Replies

 
Jakob Westhausen
Reply

I found the solution by using the GetPageviewByPageID and Output method:

@Dynamicweb.Frontend.PageView.GetPageviewByPageID( [ID] ).Output();

 
Mikkel Ricky
Reply

@Global:Page.Content has worked like this since the dawn of time (cf. http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/General-tags/Global-template-tags/GlobalPage-Content(ID).aspx).

Glad that you found a solution. I'm curious: why do you need to render a page into another page?

Best regards,
Mikkel

 
Jakob Westhausen
Reply

This is a bit of a corner case. The customer has a wide range of different forms and dependent on a specific product value one or more forms must be rendered in the checkout flow.

 

By the way, how can I access an item list or item property from CartV1 module?

I have tried: 

var pageItem = Dynamicweb.Frontend.PageView.Current().Item;

pageItem["SomeProperty"].ToString();

But it dosen't work, is it because I use CartV1?

 
Mikkel Ricky
Reply

@Pageview.Item (which is much easier to write than @Dynamicweb.Frontend.PageView.Current().Item) should work in any template.

What does

<pre>@Newtonsoft.Json.JsonConvert.SerializeObject(Pageview.Item, Newtonsoft.Json.Formatting.Indented)</pre>

show in your CartV1 template?

Best regards,
Mikkel

 
Jakob Westhausen
Reply

<pre>@Newtonsoft.Json.JsonConvert.SerializeObject(Pageview.Item, Newtonsoft.Json.Formatting.Indented)</pre> returns null.

So if my item property i called "ThemeAdsl" this should output the value?

<div>@Pageview.Page.PropertyItem["ThemeAdsl"]</div>

The div is empty :(

 
Mikkel Ricky
Reply

Does

<pre>@Newtonsoft.Json.JsonConvert.SerializeObject(Pageview.Page.PropertyItem, Newtonsoft.Json.Formatting.Indented)</pre>

show anything useful? Do you have a solution we can take a look at?

 
Jakob Westhausen
Reply

Now I just output:

Error compiling template "Designs/sgts/eCom/Cart/Customer.cshtml"
Line 106: Identifier expected
Line 106: Invalid expression term '/'
Line 106: ) expected
Line 106: Invalid expression term ','
Line 106: ; expected
Line 106: ; expected
Line 106: Invalid expression term ')'
Line 106: ; expected
Line 106: Invalid expression term ')'

 

Is it bacuase I'm using an item paragraph with a module on it?

 
Jakob Westhausen
Reply

By doing this instead:

<pre>@Newtonsoft.Json.JsonConvert.SerializeObject(Pageview.Page.PropertyItem, Newtonsoft.Json.Formatting.Indented)</pre>

I get:

{
  "Id": "57",
  "Sort": 0,
  "ItemInstanceType": "",
  "NotInUse": ""
}
 
Mikkel Ricky
Reply

It seems that your page property item only contains one field, "NotInUse" (apart from the built-in system fields). Do you see more/other fields when editing the page properties?

 
Jakob Westhausen
Reply

That's weired.

I have uploaded some screenshots of the item paragraph with the CartV1 module attatched.

As you can see there are many item properties, eg. "Headline", "ThemeComputer", "ThemeAdsl".

Screen_Shot_2014-12-11_at_08.13.14.png Screen_Shot_2014-12-11_at_08.13.27.png
 
Mikkel Ricky
Reply

Ok, so you're using an item based paragraph and want to access the item data of this paragraph, right?

The paragraph item data is not available in the module template and nor is the paragraph id (afaik) which would be useful for loading the item data manually. However, you can get the item data using something like this

@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>

@functions {
    // Get first paragraph on page with the specified module system name
    Dynamicweb.Content.Paragraph GetParagraphByModuleSystemName(string moduleSystemName, int pageId)
    {
        var paragraphs = Dynamicweb.Content.Paragraph.GetParagraphsByPageID(pageId);
        if (paragraphs != null)
        {
            foreach (var paragraph in paragraphs)
            {
                if (paragraph.ModuleSystemName == moduleSystemName)
                {
                    return paragraph;
                }
            }
        }
        return null;
    }

    // Get item from first paragraph on page with the specified module system name
    Dynamicweb.Content.Items.Item GetItemByModuleSystemName(string moduleSystemName, int pageId)
    {
        var paragraph = GetParagraphByModuleSystemName(moduleSystemName, pageId);
        if (paragraph != null && !string.IsNullOrEmpty(paragraph.ItemType) && !string.IsNullOrEmpty(paragraph.ItemId))
        {
            return Dynamicweb.Content.Items.ItemManager.Storage.GetById(paragraph.ItemType, paragraph.ItemId);
        }
        return null;
    }
}

@{
    // Example use
    var moduleSystemName = "ItemPublisher";
    var paragraph = GetParagraphByModuleSystemName(moduleSystemName, Pageview.Page.ID);
    var item = GetItemByModuleSystemName(moduleSystemName, Pageview.Page.ID);
}

<pre>paragraph: @paragraph
item: @Newtonsoft.Json.JsonConvert.SerializeObject(item)</pre>

I'll make a product backlog item for us to consider making paragraph item data available in module templates, but I cannot promise anything yet.

Best regards,
Mikkel

 
Jakob Westhausen
Reply

I have an item based paragraph with a module attacted, and from the module (CartV1) I want to access the item properties.

Is that possible?

 

I have also tried creating a page item with a module attacted, but I still can't access the item properties from the module.

 
Mikkel Ricky
Reply
This post has been marked as an answer

Have you seen my post from yesterday morning with an example on how to get the item properties from a paragraph?

@Pageview.Page.Item will give you the item of the current page (if it's item based) and @Pageview.Page.PropertyItem will give you the property item for the page if it exists.

Which version of Dynamicweb are you running?

Best regards,
Mikkel

Votes for this answer: 1
 
Jakob Westhausen
Reply

I have tried your example, but it returns this error:

Error compiling template "Designs/sgts/eCom/Cart/Customer.cshtml" Line 220: A local variable named 'item' cannot be declared in this scope because it would give a different meaning to 'item', which is already used in a 'child' scope to denote something else

@Pageview.Page.Item or @Pageview.Page.PropertyItem returns nothing.

 

 
Jakob Westhausen
Reply

@Pageview.Page.Item works if I use a page item!

Thanks a million Mikkel :)

 
Jakob Westhausen
Reply

Now I just need to figure out how to access a item list from the module..

This dosen't work:

@foreach( LoopItem i in GetLoop( Pageview.Page.Item["PaymentList"] ) ) {

}

Any ideers?

 
Mikkel Ricky
Reply

Check out this reply in another post: http://developer.dynamicweb.com/forum/development/re-itemmanager-storage-getbyid-interate-through-itemlist.aspx#Reply38853

Best regards,
Mikkel 

 

You must be logged in to post in the forum