Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Oct 01, 2012 @ 14:04
    Anthony Candaele
    0

    check if macro IsLast

    Hi,

    I'm using a property of type macro container.

    Accessing macro parameters in Razor is easy:

    var title = Parameters.title

    However, the data of the last macro needs to get a class="last", so how can I determine if the macro is the last one?

    My xlm in Umbraco.config looks like this:

    <homepageBox><![CDATA[<?UMBRACO_MACRO  macroalias="HomeBox"  title="About ESHMS"  image="1059"  intro="A small group of devoted, internationally active scientists involved in socio-medical research initiated the foundation of European Society of Medical Sociology (ESMS) in the early 1980ies. "  link="1054"  /><?UMBRACO_MACRO  macroalias="HomeBox"  title="Apply for membership"  image="1094"  intro="ESHMS members benefit from a registration fees reduction for the biannual ESHMS Congress"  link="1056"  /><?UMBRACO_MACRO  macroalias="HomeBox"  title="Conferences"  image="1287"  intro="Past and upcoming conferences of the ESHMS"  link="1100"  />]]></homepageBox>

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 01, 2012 @ 15:07
    Anthony Candaele
    0

    maybe I should restate my question,

    I there a way to loop through the above macro's in a razor script file (.cshtml)

    thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Oct 01, 2012 @ 16:45
    Anthony Candaele
    0

    ok, I will restate my question yet another way,

    In Xslt there is a way to determine if a macro is the last one:

    <xsl:if test="position() = last()">

           <xsl:attribute name="class">box no_margin</xsl:attribute>

         </xsl:if>

    Is there a way to achieve this for a macro in a Razor script (.cshtml)

    Thanks for your help,

    Anthony

  • WestLifeUmbraco 39 posts 70 karma points
    Nov 06, 2012 @ 18:15
    WestLifeUmbraco
    0

    Do you find the solution? I have the same problem.

  • Anthony Candaele 1197 posts 2049 karma points
    Nov 06, 2012 @ 18:28
    Anthony Candaele
    0

    Hi pingpong

    nope, I didn't found the solution :(

    Anthony

  • WestLifeUmbraco 39 posts 70 karma points
    Nov 06, 2012 @ 18:42
    WestLifeUmbraco
    0

    One possible solution but not ideal is to parse the string of macro container, and compare the id in the macro container string with the required node id.


    E.g. not real code below

      string macroContainer = Model.macroContainerAlias
      //parse the macroContainer here,
     
    The problem is there is no object type for macro container.

     

    Another way is to put a macro A after the macro for the macro container, and put logic within macro A.

     

    Hope there are Macro Container APIs rather than using hacks.

     

    Hope it helps.

Please Sign in or register to post replies

Write your reply to:

Draft