Developer forum

Forum » Templates » Dynamicweb.Extensibility.Subscribe...Crossing over from Paragraphs to Pages

Dynamicweb.Extensibility.Subscribe...Crossing over from Paragraphs to Pages

Kevin O''Driscoll
Reply

Heres a thing... Ive been using Custom Tags to create output at page level using [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.AfterOutput)] and OnOutput

All is good, and I can set some Paragraph tags at the Para level too - Dynamicweb.Notifications.Standard.Paragraph.OnBeforeRender

Now I want to set some page level content dependent on a Paragraph output.

Im using the NewsV2 module on a Para and trying to create a News Headlines "Navigation" Menu in a sidebar on a page.

The Page Template is generic used all over the site but I could render this conditionally if a news module is attached to a Para on the page and I can set a custom tag If Defined... in the Page

// Set a Custom tag in the page that hosts a specific Custom Module in a Paragraph
            if (paragraph.ParagraphModuleSystemName.ToString() == "NewsV2")

Then I go off and get some content from some settings on the module and add Tags to my tagCollection - all good so far

So now I have my tag set at Para level and the values I want. The trick is to get this added to [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.AfterOutput)] or OnOutput  routines

I thought I could:

Dynamicweb.Notifications.Standard.Page.OnOutputArgs args = new Dynamicweb.Notifications.Standard.Page.OnOutputArgs;
                    args.template.Tags.Add(tagCollection);

But no not possible. There must be way to add some Para Tags to Page Tags?


Replies

 
Mikkel Ricky
Reply

You could try using a snippet for this:

In your page template you add <!--@Snippet(SidebarNavigation)--> in your sidebar. In your news template you add content to this snippet

<!--@SnippetStart(SidebarNavigation)-->
<h1>News headlines</h1>
<ul class="news-headlines">
<!--@LoopStart(...)-->
<li>
<!--@LoopEnd(...)-->
</ul>
<!--@SnippetEnd(SidebarNavigation)-->

This will let you render content in your news template, but display it in your page template.

Update: Here's the documentation on snippets: http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Snippet.aspx

Best regards,
Mikkel

 
Kevin O''Driscoll
Reply

Hi Mikkel thanks for this.. I already tried a snippet hoping this was true:

<!--@SnippetStart(NewsNavigation)-->
<h2><a href='#recentnews' class='divide-toggle'>Recent News </a></h2>
<div class='divide-content' id='recentnews'>
    <nav role='navigation' aria-label='Section Navigation'>
        <ul>
            <!--@LoopStart(NewsList)-->
            <li>
                <a id="news<!--@News:ID-->" href="<!--@News:Href-->"><!--@News:Heading--></a><time datetime="<!--@News:Date.ShortDate-->"> (<!--@News:Date.MediumDate-->)</time>
            </li>
            <!--@LoopEnd(NewsList)-->
        </ul>
    </nav>
</div>
<!--@SnippetEnd(NewsNavigation)-->

 

All is fine when on the List Page, but when you click through to the details, NewsList is a list of one....so my navigation becomes worthless  8-(

 
Mikkel Ricky
Reply

Oh, missed that one … We can do it using two news lists on the page: one for the list (navigation) and one for the details.

You may have noticed the PID query parameter in the news details url, e.g. ?PID=1066&M=NewsV2&Action=1&NewsId=3. This parameter makes the other parameters only have effect for the module on the paragraph with id 1066, i.e. only the module on paragraph 1066 will show the details and any other news modules on the page will show the default view (list in this case).

So a way to do it is this: Add two news modules to the page and make sure they have the same settings apart from the list template. In the navigation news module, you change the news details url (@News:Href) to target the other news module on the page. For testing purposes you can use something like

<!--@News:Href.Replace("PID=1062","PID=1066")-->

in the template, but you should not hard code the paragraph ids in the final solution.

By the way, this would be much easier to with item based news (cf. http://items.dynamicweb.dk/). Have you considered doing it using items?

Best regards,
Mikkel

 

 

You must be logged in to post in the forum