3 Block Instance Finder Shared by Jon Corey, Lakepointe Church 7 months ago 13.0 General Intermediate This recipe is an adaptation of a recipe by Randy Aufrecht at ONE&ALL Church (https://community.rockrms.com/recipes/80/removing-staff-from-rock). Have you ever changed a setting on a block and then had to dig through your pages to find all of the other blocks that also needed that setting changed? Or have you made a change to a block's code and wanted to make sure it still works on every page you have it on? I have created a simple solution that may be what you are looking for. I have created a page with a block type picker workflow form and a dynamic data block that finds each instance of that block type and displays the information nicely. Creating this for yourself Workflow The block type picker workflow is a simple workflow form with a block type picker that adds query strings to the URL when the 'Filter' button is clicked. Here are some screenshots of the workflow so that you can see how it does what it does. There is a download button below where you can download the workflow and then import it into your Rock. Page The next step is setting up the page. We have this page under Admin Tools > Database Tools so that it is quick and easy to reach for our Rock admins, but you can put it wherever is best for you. Now, we add a Workflow Entry block to the page and assign the workflow we just created as the Workflow Type in the block's settings. Dynamic Data Block Next, we add a Dynamic Data block to the page. In its block settings, make sure to check 'Rock Entity' under 'Enabled Lava Commands'. In the contents of the block, add the following SQL as the 'Query' attribute: IF @BlockType != '' SELECT bl.BlockTypeId, bl.PageId, bl.Name as'BlockName', bl.Id as 'BlockId', pg.InternalName as 'PageName', blt.Name, blt.Description, blt.Category, blt.Path FROM [Block] as bl JOIN [Page] as pg on bl.PageId=pg.Id JOIN [BlockType] as blt on bl.BlockTypeId=blt.Id WHERE BlockTypeId = @BlockType ORDER by bl.PageId This is what actually gets the data we need for finding where each block of the selected type is. Next, put BlockType= into the 'Parameters' field. This is what reads the block type id from the query string and passes it to the SQL. Now, check the 'Customize Results with Lava' toggle and paste the following into the 'Formatted Output' field that appears: {% assign results = rows | Size %} {% if results != 0 %} {[ panel title:'Block Instances']} {% for row in rows %} {% capture editurl %}/admin/cms/pages?Page={{row.PageId}}{% endcapture %} {% capture gourl %}/page/{{row.PageId}}{% endcapture %} {{ row.PageName }} Block Name: {{row.BlockName}} Block ID: {{row.BlockId}} Page ID: {{row.PageId}} {% page where:'Id == {{row.PageId}}' %} {% for page in pageItems %} {% assign current = page %} {% endfor %} {% endpage %} {% assign array = Items | AddToArray:current.InternalName %} {% for x in (0..20) %} {% assign current = current.ParentPage %} {% if current == null %} {% break %} {% else %} {% assign array = array | AddToArray:current.InternalName %} {% endif %} {% endfor %} {% for item in array reversed %} {% if forloop.last %} {{ item }} {% else %} {{ item }} > {% endif %} {% endfor %} {% endfor %} {[ endpanel ]} {[ panel title:'Block Type Info']} {% assign lastRow = rows | Last %} ID: {{ lastRow.BlockTypeId }} Name: {{ lastRow.Name }} Description: {{ lastRow.Description }} Category: {{ lastRow.Category }} Path: {{ lastRow.Path }} {[ endpanel ]} {% endif %} The lava is what takes the data from the SQL query and formats it to make it nicely laid out and easy to read. After all of the steps above have been completed, you should have a page that helps you to find every instance of a selected block type. Download File
Kevin Rutledge Reply 4 months ago You can avoid the workflow by using the page parameter filter block.
Myles Svendsen 2 months ago Thanks for this suggestion. The workflow was not advancing past the first action (Get Block Type) on our v14.1 system.