I wonder what you are looking for? It seems you already have everything you need.
List of blocks on a page -> Model.Content.ContentBlocks.Header +
Model.Content.ContentBlocks.Blocks (this assumes you use
ModelsBuilder and the property alias is "contentBlocks").
Without ModelsBuilder you can use: IPublishedContent content = ...; var contentBlocks =
content.Value<IContentBlocks>("contentBlocks").
You probably want to add some unique id to each content block you render, so you can use JavaScript to navigate to it. For example, in your partial views that you use for the content blocks you can just add something like this:
@inherits UmbracoViewPage<IContentBlockViewModel<...>>
<div data-block-id="@Model.Id">
... block content here
</div>
And then use JS to scroll the window to the top of the content block div when you click on your navigation list.
Each ContentBlock can just render the <section id="..."> right (in their partial view)? So that's that. Then the only thing you need to do is somehow render that <ul> in your _Layout file, right? In your Layout you can just read the ContentBlocks of the current page using @Model.Content.Value<IContentBlocks>("contentBlocks"), so I am not sure what other information you are looking for?
If you debug using Visual Studio you can inspect the variables that would make your life much easier I think.
Anyway, IContentBlocks is not an Enumerable. It has a .Header property for the Header ContentBlock and a .Blocks which IS an IEnumerable of all IContentBlockViewModels. So instead of perplexBlocks.Any() try perplexBlocks.Blocks.Any(). Just keep in mind this does not include the Header block (which is perplexBlocks.Header).
Get a list of used Perplex elements
Usually we just let render the content of the Perplex elements, but now we would like to use them as an anchor sub navigation on a onepager.
We use Umbraco 9.5.0 with Perplex.ContentBlocks 2.1.5
Can anyone give us a hint, how or where we get a start to find a solution.
Thanks all
Hi,
I wonder what you are looking for? It seems you already have everything you need.
List of blocks on a page -> Model.Content.ContentBlocks.Header + Model.Content.ContentBlocks.Blocks (this assumes you use ModelsBuilder and the property alias is "contentBlocks").
Without ModelsBuilder you can use: IPublishedContent content = ...;
var contentBlocks = content.Value<IContentBlocks>("contentBlocks")
.You probably want to add some unique id to each content block you render, so you can use JavaScript to navigate to it. For example, in your partial views that you use for the content blocks you can just add something like this:
And then use JS to scroll the window to the top of the content block div when you click on your navigation list.
Hope this helps.
Hi Daniël
Thanks a lot for your quick reply, and sorry for my unclear problem description.
Your answer 2 helps me already a little bit, but I am unsure if i know everything I will need.
What I like to achieve is something without JavaScript:
And in the body
Each ContentBlock can just render the
<section id="...">
right (in their partial view)? So that's that. Then the only thing you need to do is somehow render that<ul>
in your _Layout file, right? In your Layout you can just read the ContentBlocks of the current page using@Model.Content.Value<IContentBlocks>("contentBlocks")
, so I am not sure what other information you are looking for?Thanks Daniël
Your guessing right. I tried something like the following:
But it doesn't work because IContentBlocks has no GetEnumerator. I tried also
and
but I am stucked.
Is there a special using directive?
I use
Kind regards
Jan
Hi Jan,
If you debug using Visual Studio you can inspect the variables that would make your life much easier I think.
Anyway, IContentBlocks is not an Enumerable. It has a
.Header
property for the Header ContentBlock and a.Blocks
which IS an IEnumerable of all IContentBlockViewModels. So instead ofperplexBlocks.Any()
tryperplexBlocks.Blocks.Any()
. Just keep in mind this does not include the Header block (which isperplexBlocks.Header
).Thanks a lot Daniël
.Block was the thing I was looking for.
My slightly simplified solution for the submenu in the navbar looks like:
I hope this may also help other coders.
is working on a reply...