Copied to clipboard

Flag this post as spam?

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


  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Jul 09, 2015 @ 09:45
    Søren Kottal
    0

    Render unique id for Macro Partials

    Is it possible to generate a unique id per instance of ie. a macro partial?

    Say I want to use a macro for generating a list of thumbnails. I want to be able to target these (and only these) thumbnails in a javascript.

    Like the following

    var myId = GenerateMyUniqueId();
    
    <div id="gallery-@myId"></div>
    
    <script>
    $(function() {
    $("#gallery-@myId").doSomething();
    });
    </script>
    

    I know I can generate a guid through Guid.NewGuid(), but this changes at every reload. I need a solution, where I get a persistent Id for the specific instance of the partial. Is that possible?

  • Carl Jackson 139 posts 478 karma points
    Jul 09, 2015 @ 12:31
    Carl Jackson
    0

    Are you passing any parameters to the macro, could one of these be used?

    What calls the macro - if you are in a loop why not iterate an ID and pass it as a macro parameter?

    Your code suggests a gallery of some sort - which I presume is related to images? can you se the media id from umbraco? or is it a higher level than this?

    Tell us some more about your structure and how things are called.

  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Jul 26, 2015 @ 18:46
    Søren Kottal
    0

    I have another use case for this problem.

    Say I have a landing page, where I want several call to action points (a simple form with an email input).

    If I create a macro for the call to action point and use it to post to the page itself, the posting functionality will be run for every call to action point.

    Think of code like this inside the macro

    @if (Request.Form["mode"] == "send") {
       DoSomething();
    }
    <form method="post">
       <input type="hidden" name="mode" value="send"/>
       <input type="submit"/>
    </form>
    

    If I add that macro ie. in 3 different places on the page, and the user submits one of them. They all will catch that the form was submitted and run the DoSomething function.

    What I would like to do is this to add a hidden input type with an id of the single instance of the macro, to use in the if part. Like this:

    @if (Request.Form["mode"] == "send" && Request.Form["macroInstanceId"] == macroInstanceId)
    

    Do you get, what I mean?

Please Sign in or register to post replies

Write your reply to:

Draft