elgentos / magento2-prismicio

Magento 2 Prismic integration
GNU General Public License v3.0
38 stars 18 forks source link

Document not being rendered when using StaticBlock #75

Closed lphilippo closed 1 year ago

lphilippo commented 2 years ago

Hello,

We're struggling with an issue that is probably and hopefully quite straightforward.

In order to try out he integration with Prismic.io, we have created a custom type and published a single content item.

We then only intend to display it as a StaticBlock, by using:

            <block class="Elgentos\PrismicIO\Block\StaticBlock">
                <arguments>
                    <argument name="data" xsi:type="array">
                        <item name="identifier" xsi:type="string">home-page</item>
                        <item name="content_type" xsi:type="string">homepage</item>
                    </argument>
                </arguments>
            </block>

Unfortunately the output is empty.

By tracing the logic in StaticBlock.php we do see that the document information is correctly received (in fetchChildDocument()), but $this->getChildNames() consequently returns an empty array.

In the document data that we see, we also seem to be missing anything that indicates the design (for example, HTML and CSS).

Would you happen to know what obvious part we are missing or skipping here? The module version we're working with is 1.9.2, Magento 2.4.5 and a Hyva-based theme (should not be relevant, but just in case)

JeroenBoersma commented 2 years ago

Hi @lphilippo thanks for the question...

Elgentos\PrismicIO\Block\StaticBlock is just a document loader...

Within the block you need to add the actual template or groups or slices.

If you just want to test if the document is loaded correctly and if your store is in developer mode.

            <block class="Elgentos\PrismicIO\Block\StaticBlock">
                <arguments>
                    <argument name="data" xsi:type="array">
                        <item name="identifier" xsi:type="string">home-page</item>
                        <item name="content_type" xsi:type="string">homepage</item>
                    </argument>
                </arguments>
                <block class="Elgentos\PrismicIO\Block\Debug">
            </block>

This should show up as debug information in the frontend.

JeroenBoersma commented 2 years ago

A more complete example would be:

A static block in Prismic with:

<block class="Elgentos\PrismicIO\Block\StaticBlock">
     <arguments>
          <argument name="data" xsi:type="array">
              <item name="identifier" xsi:type="string">home-page</item>
             <item name="content_type" xsi:type="string">homepage</item>
         </argument>
     </arguments>
     <block class="Elgentos\PrismicIO\Block\Template" template="Elgentos_PrismicIO::component/static_block.phtml">
          <block class="Elgentos\PrismicIO\Block\Dom\RichText" template="data.title" as="title" />
          <block class="Elgentos\PrismicIO\Block\Slices" template="data.body" name="static_block.slices" as="slices" />
              <block class="Elgentos\PrismicIO\Block\Container" name="static_block.slices.text">
                    <block class="Elgentos\PrismicIO\Block\Dom\RichText" template="primary.awesome" />
              </block>
          </block>
     </block>
</block>

component/static_block.phtml

<div>
<?= $block->getChildHtml('title'); ?>
</div>
<div>
<?= $block->getChildHtml('slices'); ?>
</div>
peterjaap commented 2 years ago

@JeroenBoersma that's an amazing answer! Could you add that to this repo's readme maybe so more people can find it?

lphilippo commented 2 years ago

Ah brilliant! This example definitely helps a lot and it solved some doubts we had about whether certain parts where the responsibility of Magento or Prismic

speedupmate commented 2 years ago

ok the most hard thing to understand is what is needed for successful request and that every document needs a uid added manually. thats a really static process , you already add a title to document and will duplicate that data for uid in prismic just to connect the dots . But great example explains a lot