new to umbraco dev so bear with me 🙂 i
s
new to umbraco dev so bear with me 🙂 i've managed to create rcl package with custom property edt / datatype. So content manager can set the value for it on a page and it is saved. All good there. However where I have my doubts if I am doing it the correct way is providing the front end part for the site visitor the content editor sets the value for the page. the page offcourse has its template (cshtml) in Umbraco settings. What we did now is getting the value from the prop editor and send that to the partial in the RCL plugin to render. simplified like: @{ var viewData = new ViewDataDictionary(ViewData); viewData.Add("parameter1", Model.Value("s4atestplugin")); } @Html.Partial("Partials/pluginpartial.cshtml", Model, viewData) Is this how it should be done? I've read about propertyconverters but do not really understand if that is what I am or should be looking for. Sometimes it can be advantage, but also it can be disadvantage that the partial is compiled into the rcl dll. So the template cannot be changed by the user of the plugin. (other than via css etc)
m
Think with umbraco/uForms there is an override mechanism for having a cshtml file in a corresponding position in the site structure. Perhaps you can leverage that to provide template tweaking by the end user?
j
I think most packages leave the frontend implementation up to the user. So they just return a model for the property and do not implement it in a view
s
our front end is part of the project. think of it as articles, blogs, front end crm functions, product pages, etc not really something for end user. But for the discussion and sample project lets just say we do something like: content editor sets via the prop editor a categorie to show on the page. So on the page we will provide a list of articles for this choosen category. user clicks on article in list and is forwarded to the detail page for the article. the content comes from different datasouces and the plugin takes care of that.
and if you would just return a model and not the view is it possible to provide a sample view from a RCL project (bit like starterkit maybe?) to get the user on the right path?
And I wonder how this would work for say a simple google maps plugin. you would let the content editor set things like default zoom, set pins on the map etc. but there must be something that puts the map on the page and use those settings set by content editor? or am I wrong?
j
In that case you would probably either document for the user what they need to set up or include a view in the RCL. As @Mike Chambers mentioned above - the Umbraco Forms package includes a view for rendering the forms. The thing about RCLs is that they only place the view there if it doesn't already exist at the target location, so users can adapt the view by pasting it into the same location and changing it.
s
ah wow "so users can adapt the view by pasting it into the same location and changing it." << this might just be the thing I was looking for
and the property converter is not related to what I am doing?
also little side note: doesn;t that make it a little bit to technical for non tech people that would want to use Umbraco to build there site?
j
This is standard RCL functionality so not really an Umbraco thing. PropertyValueConverters wouldn't solve your specific usecase but it basically allows you to convert whatever is saved in the database into a model before it is received in the frontend. So say you create a new property editor for an integration with a PIM where the user can select a product - then you may not want to then save an entire product model into the property in the database when the node is saved as that would just be a snapshot of the data at the time the editor saved it. Instead you may save a SKU fx. Then in a PropertyValueConverter for that custom property editor you could get the sku, fetch the product from the PIM and return a full product model - which would then be up to date data for the time of rendering. (Note that the valueconverter is hit every time the property is called, so in this scenario you would want to cache the fetch from the PIM)
s
"This is standard RCL functionality so not really an Umbraco thing." I ment more the not including a view for the frond end in a plugin.
Thank you for the info on the converter. it is more or less what I understood of it. and indeed when I include the partial view in my rcl I do not need that. I only save the key. the key is passed as argument to the partial razor page and from there we get the full model. where possible we would use caching but I am not that far into Umbraco yet 🙂
I must say I am impressed by the help I am getting here from the community
And taking it 1 step further.. how would this work if they use say the blockbuilder?
you make a plugin that has to render things to the end user.
somehow your view will have to be able to be placed somewhere in a block?
j
Yea that is one of the problems of including view code, the way Umbraco Forms gets around this is to include a viewcomponent, a taghelper and a macro all pointing to the view they included. Then they document for the user what they need to put in their view for the block / page where the property is used: https://docs.umbraco.com/umbraco-forms/developer/rendering-forms
s
read about macro's not the taghelper.. thanks for pushing me in the right direction of the forms module. I will have a look on how they do it.
we are just used (we come from DNN) that the front view is registred in the backoffice and thus it is simply selecting what view you want to use for frond end users and voila
Umbraco is little more tech minded maybe and that is good for us web devs but if your user wants to do more themselves (without the right knowledge) or use things like blockview it gets tricky
Macro seems to be what I need to do. Just wonder if this stayes when the new Umbraco backoffice is a fact
j
It will not, I would personally pick the taghelper approach I think
s
oke thank you for thinking along on this. I will look into the taghelper option
btw.. solved it differently. added the prop editor to blockgrid as configuration blocks then partial views/blockgrid/Components > added partial view loading the partial view from the razor class library and sending the configuration via viewdata. works like a charme. now the content editor can simply add it scale it move it for example to column etc and configure the settings.
3 Views