we use something like along these lines.. to calc length of macroContainer.. (note the "_" is just for recursion and you might not be parameterising the MacroContainerName... so you may or may not need)
//split into the separate macros
int macroCount = 0;
string[] macros = new string[] {};
try{
string macro = Model.GetProperty("_"+Parameter.macroContainerName).Value.Replace("><", ">$<");
macros = macro.Split(new string[] { "$" }, StringSplitOptions.RemoveEmptyEntries);
macroCount = macros.Length;
}catch{}
so each macro... added to the macroContainer ends up as <?UMBRACO_MACRO macroalias="XXX" {...All my params} />
So in effect all i'm doing is intercepting this and parsing.. and then rendering outside of the standard render method from the umbraco core for a macroContainer.
I hope that explains it a little more?
(ps this was from umb 4, maybe things have changed in u7?)
MacroContainer
Hi all,
I am not sure this is the correct place to ask, but here goes :)
I am using 7.2.1 and razor.
What I need is to be able to access the length of the MacroContainer so that I can choose layouts,
eg. I have a different layout for 2 vs 4 macros in the container :)
Is there any way to access the macrocontainer itself?
regards,
garpur
we use something like along these lines.. to calc length of macroContainer.. (note the "_" is just for recursion and you might not be parameterising the MacroContainerName... so you may or may not need)
//split into the separate macros int macroCount = 0; string[] macros = new string[] {}; try{ string macro = Model.GetProperty("_"+Parameter.macroContainerName).Value.Replace("><", ">$<"); macros = macro.Split(new string[] { "$" }, StringSplitOptions.RemoveEmptyEntries); macroCount = macros.Length; }catch{}Just thought.. you might also want this... for then rendering macros...
Thank you for the trick Mike,
this however depends on no part of my macro partial html having "><" and is therefore brittle :)
I will use it and submit a feature request for the team to provide more access to the container.
cheers
Garpur
Not sure we are talking about the same thing here then... the "><" has nothing to do with content in the macro partial...
I thought you were talking about use of the MacroContainer Datatype..
if you write out the rawtext... of a doctype param set to use the macroContainer datatype
@Html.Raw(Model.GetProperty("_"+Parameter.macroContainerName).Value)you end up with something like this (a page with 8 macros in the MacroContainer...)
<?UMBRACO_MACRO macroalias="AbrAbstract" node="1065" hideImage="1" hideMore="1" hideMainHeading="1" wrapperClass="abstract-feature intro" spanClass="span6" thumbnailType="Square Crop" btnClass="0" altHeading="" /><?UMBRACO_MACRO macroalias="AbrAbstract" node="1246" hideImage="1" hideMore="1" hideMainHeading="1" wrapperClass="abstract-feature-info" spanClass="span6" thumbnailType="Small Rectangle Crop" btnClass="0" altHeading="" /><?UMBRACO_MACRO macroalias="AbrAbstract" node="1253" hideImage="0" hideMore="1" hideMainHeading="0" wrapperClass="abstract-feature-image" spanClass="span4" thumbnailType="Small Rectangle Crop" btnClass="0" altHeading="" /><?UMBRACO_MACRO macroalias="AbrAbstract" node="1254" hideImage="0" hideMore="1" hideMainHeading="0" wrapperClass="abstract-feature-image" spanClass="span4" thumbnailType="Small Rectangle Crop" btnClass="0" altHeading="" /><?UMBRACO_MACRO macroalias="InvestorFeedsTabs" wrapperClass="" spanClass="span4" /><?UMBRACO_MACRO macroalias="AbrAbstract" node="1251" hideImage="1" hideMore="1" hideMainHeading="0" wrapperClass="abstract-feature-text-only" spanClass="span3" thumbnailType="Large Rectangle Crop" btnClass="0" altHeading="" /><?UMBRACO_MACRO macroalias="UsefulLinks" spanClass="span3" wrapperClass="list abstract-feature-links" altHeading="" /><?UMBRACO_MACRO macroalias="AbrList" node="1245" hideListHeading="0" altHeading="" aggregated="0" limitItemsToX="" hideDate="0" hideImage="1" thumbnailType="Large Rectangle Crop" spanClass="span3" wrapperClass="list abstract-feature" hideAbstract="1" abrLength="" hideRSS="1" showParentAbstract="0" gridSize="" /><?UMBRACO_MACRO macroalias="ContentSlider" node="2301" sliderId="highlights" hideImage="0" hideTable="0" hideMore="0" hideMainHeading="0" hideArrows="0" hidePills="0" spanClass="span3" altHeading="" panelClass="" wrapperClass="highlights-panel" />so each macro... added to the macroContainer ends up as <?UMBRACO_MACRO macroalias="XXX" {...All my params} />
So in effect all i'm doing is intercepting this and parsing.. and then rendering outside of the standard render method from the umbraco core for a macroContainer.
I hope that explains it a little more?
(ps this was from umb 4, maybe things have changed in u7?)
Hi,
Things have changed :( :p :)
All I get is the html, I can't find any GetProperty on the Model, but I can still make this work (just a bit brittle).
I'll take a look at the C# source for the container and see if I can just extend that, I was just hoping to not have to do that :)
thx
garpur
had a look into it.. and had to go a little round the houses...
In a template.... @CurrentPage.macroContainer and GetProperty etc... as you say returns the rendered content of all the macros..
However, second gives me that <?Umbraco_Macro /> list that I can use... (still using the xml cache and not DB acess as using the nodeFactory)
@{ @CurrentPage.macrocontainer umbraco.NodeFactory.Node n = new umbraco.NodeFactory.Node(CurrentPage.id); @(n.GetProperty("macrocontainer").Value) }test
Posting what I ended up doing for others to find :p
@{
.. other stuff
var rawNode = new umbraco.NodeFactory.Node(CurrentPage.id);
var macros = rawNode.GetProperty("MacroContainerName").Value.Replace("><", ">$<").Split('$');
var macroCount = macros.Length;
var macroWidth = "medium-3";
var macroLineWidth = "";
}
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.