Developer forum

Forum » Templates » PageVievModel - when used no paragraphs are rendered (DW 9.6.13)

PageVievModel - when used no paragraphs are rendered (DW 9.6.13)

Jacob Storgaard Jensen
Reply

When I use PageViewModel on my Master and Page templates my placeholders and their content are not rendered...

I have tested using two dead simple plain master and page templates using edit: ParagraphViewModel PageViewModel, my placeholders are not rendered, but removing the

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>

and changing the placeholder code to the "old style" makes the placeholders render...

Any ideas?

P.S. it's an existing solution with tons of paragraphs and templates that I've taken over... And it uses old-style paragraphs alot, which will take ages to change...

 


Replies

 
Nicolai Pedersen
Reply

Maybe have a look at this page:

https://doc.dynamicweb.com/template-tags/introduction/concept/viewmodels#4483

BR Nicolai

 
Jacob Storgaard Jensen
Reply

Just edited my question. I did use PageViewModel not ParagraphViewModel...
But I've done everything as it says in the docs... And I've tried having only one paragraph that uses ParagraphViewModel too... doesn't work... Will try the same templates on another site...

 

 
Jacob Storgaard Jensen
Reply

Okay... this is weird...

I changed:

@Model.Placeholder("content-main", "Main content", "default:true;sort:1")

to:

@Model.Placeholder("dwcontent", "Main content", "default:true;sort:1")

reloaded the page and my content rendered...

In the old days we had to have dwcontent as a class on the placeholder element... but in the ViewModels docs it says:

@*A content placeholder with a title and a description *@
@Model.Placeholder("main", "Main content", "default:true;sort:1")

A placeholder can take the following parameters:

Parameter

Required

Comments

Id

Yes

Unique id of a layout container.

Title

No

Friendly name of the layout container which is displayed in the administration (defaults to the value of Id).

Settings

No

Additional settings that specifies how the content should be rendered.

 

 

 

 
Konstantin Landyshev
Reply

Hi

I'll try to describe how this feature works:

1. Create new page.

2. Create and select as layout new Page template,  where you will write next lines:
 

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>


@Model.Placeholder("Main", "Main content", "default:true;sort:1")

@Model.Placeholder("Left", "Left content")

​@Model.Placeholder("Right", "Right content")


2. When you will open your page in Content tree you will see next result (IMG)

As you can see there are 3 content blocks. These blocks based on your placeholders in page template. You can create paragraphs for each content block. As I understand your problem (nothing renders) - it is because all of your paragraphs was placed in the base (standart) content block named "dwcontent".

Best regards
Konstantin Landyshev
Frontend developer

Untitled.jpg
 
Claus Kølbæk
Claus Kølbæk
Reply

I had noticed something similar in one of the latest updates -it used to work until I think 9.7? - Now I have a

@if(false){

<div class="dwcontent">

}

in the templates just to be able to select them in backend. If that is added then it works as described by Konstantin.

So ye, think it might be a small bug introduced in 9.7 - as it used to work just with the ther model.placeholders before.

 
Konstantin Landyshev
Reply

Hi

I can't reproduce any bug related to this situation. Can you please describe steps and said what the version of Dynamicweb is used?

Best regards

 
Claus Kølbæk
Claus Kølbæk
Reply

I got an express 9.7.1 running where it is an issue.

The template got a reference to a master template but else the only thing it has is pretty much this:

<div id="maincontent">
        @Model.Placeholder("maincontent", "Content", "default:true")
    </div>

and then:

@if(false) {
    <div id="ignore" class="dwcontent" title="Ignore"></div>
}

If I remove the last part, then I am no longer able to choose the template in website settings.

 
Jacob Storgaard Jensen
Reply

Yes, what Konstantin writes is how it's supposed to work :-)
In my situation it was version 9.6.13, and this was an existing solution (Azure hosted) and a existing content page, where this placeholder (content-main) was defined in the old non-View Model manner (and was the only placeholder)... And so changing this to a View Model template (master and layout) fucked something up... But it's nice to know your workaround Claus because I have alot of pages with paragraphs assigned to that placeholder... until a fix is out :-D.

 
Claus Kølbæk
Claus Kølbæk
Reply

I can maybe add that ours is also a solution that was upgraded from 8.x something, but it was a clean new application folder (downloaded it from the download page, as the version on the Nuget feed had some issues (yet again) and it is also currently running on azure - though I can see the problem on my local installation aswell.

 
Nicolai Pedersen
Reply

Hi

I just created a design with a master and layout like this:

MASTER

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
@using System
@using System.Web
<!DOCTYPE html>
<html>
<head>
    <body>
        @ContentPlaceholder()
    </body>
</html>

LAYOUT

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>

<!DOCTYPE html>
<html>
<head>
    <title>@Model.Title</title>
    <meta name="description" content="@Model.Description" />
    <meta name="keywords" content="@Model.Keywords" />
</head>
<body>
    <h1>@Model.Name</h1>
    <div>
        @Model.Placeholder("main")
    </div>
</body>
</html>

And it works... See dump #1.

On a page you have paragraphs - in the paragraph table you might have paragraphs from old days or from when you placeholder had an other ID. Those paragraphs will not be rendered until moved into the "main" placeholder.

We do have some "fallback" feature from old days, that will render paragraphs that does not belong to a placeholder, in the default placeholder. That might not work if you do not have something with dwcontent in your template. That 'feature' is not meant to work in viewmodel templates - we try to keep them 'clean'.

BR Nicolai

Capture.PNG

 

You must be logged in to post in the forum