I want to include the html for a modal popup at the end of the master view before the body closing tag, but only if a certain DataType or partial view is part of the completed page.
Is there a way to accomplish this in Umbraco? How do I check whether a specific DataType or partial view is part of the page?
thank you for your suggestion. The thing is that I need to make sure I add the partial only once. I can have several instances of the DataType on a page, but the modal code should be included only once.
thank you for your suggestion. However the first code line does not work for me, I get this error:
@using Umbraco.Core;
@using Umbraco.Web;
...
Error CS1061: 'IPublishedContent' does not contain a definition for 'GetPropertyValue' and no accessible extension method 'GetPropertyValue' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
I am on Umbraco 8. I have read that Model.Content.GetPropertyValue() doesn't work in V8 anymore.
What works in Umbraco 8 is apparently Model.Value(). However, it seems that this only checks direct child properties of the model itself.
What I need is checking whether a DataType is part of the rendered page anywhere. In my case, I have nested blocklists. I am looking for a way to find out whether a DataType is part of any of the blocklists on any level.
I have changed the title of my question to make the issue clearer....
What I have come up with as a solution so far is:
in the partial view rendering the DataType, a flag is set
in the master view, I check for the flag, and if it is set, the html for the modal is included
This works, howeveer it feels more like brute-force and I wonder whether there is something more Umbraco'ish to solve this.
Checking for DataType present in nested blocklists from master viewfile
I want to include the html for a modal popup at the end of the master view before the body closing tag, but only if a certain DataType or partial view is part of the completed page.
Is there a way to accomplish this in Umbraco? How do I check whether a specific DataType or partial view is part of the page?
It sounds like you might be able to achieve this using custom sections:
Hi Brendan,
thank you for your suggestion. The thing is that I need to make sure I add the partial only once. I can have several instances of the DataType on a page, but the modal code should be included only once.
Amir's solution is better :)
Do the datatypes all have the same alias on the document type? You could do a check like you would for an image if so.
Not sure on the checking if a partial view exists within a template is possible but you could render your mobile in that partial view I suppose?
Hi Amir,
thank you for your suggestion. However the first code line does not work for me, I get this error:
Any idea what I am doing wrong?
Thank you for all the input so far.
I am on Umbraco 8. I have read that
Model.Content.GetPropertyValue()
doesn't work in V8 anymore.What works in Umbraco 8 is apparently Model.Value(). However, it seems that this only checks direct child properties of the model itself.
What I need is checking whether a DataType is part of the rendered page anywhere. In my case, I have nested blocklists. I am looking for a way to find out whether a DataType is part of any of the blocklists on any level.
I have changed the title of my question to make the issue clearer....
What I have come up with as a solution so far is:
This works, howeveer it feels more like brute-force and I wonder whether there is something more Umbraco'ish to solve this.
is working on a reply...