We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18817 ☆ A M B ☆
    • 205 Posts
    I want to output the string of hits. Doesn't seem to be a parameter within the snippet. I would like to have a data-hits="" attribute on a template for a getResources call.

    Example output:
    <li data-hits="55"> ... </li>


    How can this be done?


    Use Case: We're using getResources to simply output child resources. We've added data attributes to be read via jQuery to do live filters on the page. One of the filters is "most read". We want to be able to read the hits of each resource so they can be filtered by most read.

    This question has been answered by sepiariver. See the first response.

    [ed. note: mayhemchaos last edited this post 11 years, 2 months ago.]
      Sal Baldovinos
      SEO & DIGITAL MARKETING

      ARIEL DIGITAL | Maximize Your Potential
      www.arieldigitalmarketing.com
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I think it's [[+hit_count]].
      tpl - hit_key, hit_count, and id (of hit) paramters will be passed into the provided chunk for each result.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 18817 ☆ A M B ☆
        • 205 Posts
        Quote from: sottwell at Aug 13, 2015, 12:25 AM
        I think it's [[+hit_count]].
        tpl - hit_key, hit_count, and id (of hit) paramters will be passed into the provided chunk for each result.

        Tried the [[+hit_count]], but it pull the hits for the current page in and not the actual resource.
          Sal Baldovinos
          SEO & DIGITAL MARKETING

          ARIEL DIGITAL | Maximize Your Potential
          www.arieldigitalmarketing.com
          • 18817 ☆ A M B ☆
          • 205 Posts
          Current Setup:

          html_footer (chunk)
          [[!Hits? &punch=`[[*id]]`]]


          tpl_case_study_module (tpl chunk for getResource ... code cleaned up for readability)
          <li class="js-filter-grid-item" data-my-id="[[+id]]" data-page-hits="[[+hit_count]]" data-filter-tags="[[!TaggerGetTags? &resources=`[[+id]]` &rowTpl=`space_separated_tags`]]" data-title="[[+alias]]" data-pub-date="[[+createdon:strtotime:date=`%Y%m%d%H%M`]]" data-is-featured="[[+featured]]">
          	<img class="tooltip-img" src="[[+page_image]]" alt="[[+longtitle]]">
          	<h4>[[+menutitle]]</h4>
          	<p>[[+introtext:ellipsis=`75`]]</p>
          	<a class="link" href="[[~[[+id]]]]">View the Case Study</a>
          </li>
          
          [ed. note: mayhemchaos last edited this post 11 years, 2 months ago.]
            Sal Baldovinos
            SEO & DIGITAL MARKETING

            ARIEL DIGITAL | Maximize Your Potential
            www.arieldigitalmarketing.com
          • discuss.answer
            • 26681 MODX Staff
            • 123 Posts
            This *should* work:
            <li class="js-filter-grid-item" data-my-id="[[+id]]" data-page-hits="[[Hits? &hit_keys=`[[+id]]` &tpl=`hitTpl`]]" data-filter-tags="[[TaggerGetTags? &resources=`[[+id]]` &rowTpl=`space_separated_tags`]]" data-title="[[+alias]]" data-pub-date="[[+createdon:strtotime:date=`%Y%m%d%H%M`]]" data-is-featured="[[+featured]]">
            	<img class="tooltip-img" src="[[+page_image]]" alt="[[+longtitle]]">
            	<h4>[[+menutitle]]</h4>
            	<p>[[+introtext:ellipsis=`75`]]</p>
            	<a class="link" href="[[~[[+id]]]]">View the Case Study</a>
            </li>
            


            Assuming the "hitTpl" chunk has [[+hit_count]] in it, it should return the number of hits for resource [[+id]]. Let me know how it goes.
              [sepiariver.com] (https://sepiariver.com/)
              • 50881
              • 2 Posts
              Thanks Sepia!

              This is what worked for reference:
              data-page-hits="[[Hits? &hit_keys=`[[+id]]` &tpl=`hit_count`]]


              Much appreciated,
              Scott
                • 46886
                • 1,154 Posts
                Thank you for providing a working solution, and glad you got it going!

                This is one particular function that I feel is so important, and MODX has yet to simplify and provide a standardized solution. Sepia River has worked very hard on this function (sincere thanks!) and has achieved much, but documentation and extendability are both limited, so far.

                Plus I love going through recent posts and encountering your colleague's great handle. Keep in touch as ya'll progress!