Developer forum

Forum » Templates » Can't insert global element

Can't insert global element

Rasmus Andersen
Reply

Hi Dynamicweb,

I cannot insert a global element with a item-allowed string formatted with spaces:
@Model.Placeholder("Hero",  "Hero", "items-allowed: HeroRibbonItem, HeroWithTextRibbonItem; unwrap:true")

But it works when formatted like this:
@Model.Placeholder("Hero",  "Hero", "items-allowed:HeroRibbonItem,HeroWithTextRibbonItem;unwrap:true")

This looks like a bug, right?

Best regards,
Rasmus

 


Replies

 
Nicolai Pedersen
Reply

Hi Rasmus

You have a space just after the : - that might be the issue, and not the space after the ,

The setting is parsed like this - the systemnames are trimmed, so should work.

settings.Split(((char)(","))).Select(Function, s, s.Trim().ToLowerInvariant());

The entire string (items-allowed:HeroRibbonItem,HeroWithTextRibbonItem;unwrap:true) is parsed by the HttpUtility.ParseQueryString method in the .net framework, so we treat your settings as a querystring key=value so key = value will not work.

So not a bug, but we could of course try to trim your spaces, but that could cause spaces that are needed to get trimmed away.

BR Nicolai

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

I have also stumpled over this problem and it took me unnessecary time to figure out what was wrong. I would really prefer that I could enter values for the parameter "items-allowed" with out thinking on spaces. Couldn't you fix that. Thanks

 
Rasmus Andersen
Reply

Hi Nicolai and Lars,

It seems like there is an anomaly. This works when creating new paragraphs, but not when using them as global elements:

@Model.Placeholder("Hero",  "Hero", "items-allowed: HeroRibbonItem, HeroWithTextRibbonItem; unwrap:true")

As a user I am expecting the same result between the two operations.

Best regards,
Rasmus

 
Rasmus Andersen
Reply

Hi again,

On a sitenote, why not add some overloaded methods for the additional parameters instead of the settings string:

  • items-allowed as a string array or string list.
  • unwrap as a boolean
  • other parameters...

This would prevent parsing entirely.

@Model.Placeholder("Hero", "Hero", new [] { "HeroRibbonItem", "HeroWithTextRibbonItem"}, true)

As a bonus it would be much easier to discover the capabilities of the method with intellisense.

Best regards,
Rasmus

 
Nicolai Pedersen
Reply

Hi Rasmus

Does it work if you use the proper syntax?

BR Nicolai

 
Nicolai Pedersen
Reply

@Rasmus

TFS#43399 has been introduced to give you a placegholdersettings object that can be passed as a parameter:

@{
var settings = new Dynamicweb.Frontend.PageViewModel.PlaceholderSettings();
   settings.ItemsAllowed.Add("ItemType1");
   settings.ItemsAllowed.Add("ItemType2");
   settings.LimitToTemplates.Add("template1.cshtml");
   settings.Default = true;
}

@Model.Placeholder("id", "Title", settings);

Available in 9.4 end January

 
Rasmus Andersen
Reply

Hi again,

For now this works:

@Model.Placeholder("Hero",  "Hero", "items-allowed:HeroRibbonItem,HeroWithTextRibbonItem;unwrap:true")

TFS#43399 will definately help prevent this type of defect, on our part, so that is great news :)

Thanks a lot Nicolai

Best regards,
Rasmus

 

You must be logged in to post in the forum