3

I have a CMS page in which I want to show the date e.i Current date OR Date after 5 days etc. So for that I have created a template file and call inside the CMS page. It will show content in Front but in GraphQl response, it will not available.

https://www.awesomescreenshot.com/image/7156601?key=f19c0b7a0aebdc1fe91ef37c79085e5a https://www.awesomescreenshot.com/image/7156679?key=66c833a0c044b5e7738b4efd6c6fc565 https://www.awesomescreenshot.com/image/7156696?key=e448522e6ef5d584d19e2c396cef11c1 https://www.awesomescreenshot.com/image/7157210?key=ac2f2a2d431ee1cadb762e46184d4a44

graphQl Request(Query):

{
        cmsPage(identifier: "home") {
        url_key
        title
        content
        content_heading
        page_layout
        meta_title
        meta_description
        meta_keywords
      }
    }
  

Current Response:

{
  "data": {
    "cmsPage": {
      "url_key": "home",
      "title": "Home Page",
      "content": "<p>Hi, DD/MM/YYYY ''</p>\r\n<p><img src=\"http://m242.com/media/wysiwyg/images.jpeg\" alt=\"\"></p>",
      "content_heading": "Home Page",
      "page_layout": "1column",
      "meta_title": "",
      "meta_description": "",
      "meta_keywords": ""
    }
  }
}

Expected Response:

{
  "data": {
    "cmsPage": {
      "url_key": "home",
      "title": "Home Page",
      "content": "<p>Hi, DD/MM/YYYY 'Today is 04/08/2021'</p>\r\n<p><img src=\"http://m242.com/media/wysiwyg/images.jpeg\" alt=\"\"></p>",
      "content_heading": "Home Page",
      "page_layout": "1column",
      "meta_title": "",
      "meta_description": "",
      "meta_keywords": ""
    }
  }
}

CMS page Content:

<p>Hi, DD/MM/YYYY '{{block class="Magento\Framework\View\Element\Template" template="Vendor_Module::current_date.phtml"}}'</p>
<p><img src="{{media url="wysiwyg/images.jpeg"}}" alt=""></p>

Template file(/Vendor/Module/view/frontend/templates/current_date.phtml):

<?php
    echo "Today is " . date("m/d/Y") . "<be>";
?>

Do I need to create a resolver?

Thanks in advance.

1
  • Any update on this question? Aug 19, 2022 at 13:40

1 Answer 1

0

This sounds like an area issue (https://devdocs.magento.com/guides/v2.4/architecture/archi_perspectives/components/modules/mod_and_areas.html).

Because you make the request through graphql magento looks for a template file in your module in the graphql area:

Vendor/Module/view/graphql/templates

If it can't find this file it can also throw an 'Error filtering template: Invalid template file' error.

You can solve this by creating the file template

Vendor/Module/view/graphql/templates/current_date.phtml

Or

Vendor/Module/view/base/templates/current_date.phtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.