We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36788
    • 75 Posts
    I have a chunk of a buyButton and I want to use it both for resource template and inside the template/chunk used for getResources output

    At the moment the only difference is an asterisk:

    Product template:
    <form action="[[~[[*resource_id]]? &scheme=`abs`]]" method="post">                        
        <input type="hidden" name="shk-id" value="[[*id]]" />
        <input type="hidden" name="shk-name" value="[[*pagetitle]]" />
        <input type="hidden" name="shk-catalog" value="2" />
        <input type="hidden" name="shk-count" value="1" />    
        <div class="shs-price">
                <span class="shk-price">[[*price:num_format]]</span>
                <button type="submit" name="shk-submit" class="small shk-but shk-buy">Buy</button>
        </div>        
    </form>



    getResources chunk
    <form action="[[~[[+resource_id]]? &scheme=`abs`]]" method="post">                        
        <input type="hidden" name="shk-id" value="[[+id]]" />
        <input type="hidden" name="shk-name" value="[[+pagetitle]]" />
        <input type="hidden" name="shk-catalog" value="2" />
        <input type="hidden" name="shk-count" value="1" />    
        <div class="shs-price">
                <span class="shk-price">[[+price:num_format]]</span>
                <button type="submit" name="shk-submit" class="small shk-but shk-buy">Buy</button>
        </div>        
    </form>


    Later on I plan to add some extra functionality to the button and I need to have it in one place. Any suggestion how can I do this?

      • 5160
      • 118 Posts
      chris.dempsey78 Reply #2, 9 years ago
      Something along the lines of this?

      [[~[[+resource_id:default=`[[*resource_id]]`]]?...

      Untested and badly formatted I'm using a phone but you get the idea with the default output modifier.
        • 36788
        • 75 Posts
        Quote from: chris.dempsey78 at May 12, 2015, 06:10 PM
        Something along the lines of this?

        [[~[[+resource_id:default=`[[*resource_id]]`]]?...

        Untested and badly formatted I'm using a phone but you get the idea with the default output modifier.

        Good idea, thank you! Though not able to use it as I will need some filtering later (e.g
        [[+price:gte=`[[++cfg.minPriceGift]]`:then=`<input type="hidden" name="giftOption__[[+id]]__add" value="GIFT PLEASE" />`]])

        Solved it for now by replacing asterisk for the whole chunk:
        [[$buyButton:replace=`+==*`]]

        Not the best practice also.))



          • 3749
          • 24,544 Posts
          Why not just have two separate chunks? Otherwise, you're going to slow down page loads just to avoid having one more small chunk.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36788
            • 75 Posts
            Quote from: BobRay at May 14, 2015, 08:17 PM
            Why not just have two separate chunks? Otherwise, you're going to slow down page loads just to avoid having one more small chunk.
            The idea is to have the content similar for both catalog and product pages. Having 2 chunks instead of 1 and implementing the changes to the 1 chunk I will always have to remember that I have to change another chunk...
              • 3749
              • 24,544 Posts
              It's kind of a funky solution, but you could use two chunks with similar names and use a plugin connected to OnChunkFormSave that saved the alternate chunk after converting the asterisk to a + with str_replace().

              Another option might be to use a + sign in the chunk, and a plugin attached to OnWebPagePrerender that converted it to an asterisk with str_replace() only if the catalog page was being rendered.

              It seems like there should be an easier solution, but I can't think of one.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 4172
                • 5,888 Posts
                In your product-template, you could use a getResources-call and get only that one resource

                or

                you could try to use renderResources to get the list
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!