How can we print data coming from controller in homepage?

sunil
sunil Posts: 5 🧑🏻‍🚀 - Cadet

Hi Everyone, I am trying to print a simple Hello World data coming from controller and wanted it to be printed on homepage/frontend(same as in the hello world backoffice https://safari.spryker.com/learn/course/339/play/2465/hello-world-page-task-description;lp=83)but in fontend.

For that i created a folder (Demo) in src\Pyz\Yves

in that

a controller file

src\Pyz\Yves\Demo\Communication\Controller\IndexController.php

<?php

namespace Pyz\Yves\Demo\Communication\Controller;

use Spryker\Zed\Kernel\Communication\Controller\AbstractController;

class IndexController extends AbstractController
{
/**
* @return array
*/
public function indexAction()
{
return $this->viewResponse([
'helloWorldText' => 'Hello World!'
]);
}

}

and a twig file in src\Pyz\Yves\Demo\Theme\default\views\Index\index.twig

{% extends template('page-blank') %}

{{ helloWorldText }}

{% endblock %}

Now , how can i call this from home.twig or any other twig file to show this on frontend

what steps are missing in this?

Answers

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 81 🏛 - Council (mod)

    Hi Sunil,

    Here is an example in the docs.

    https://docs.spryker.com/docs/scos/dev/tutorials-and-howtos/introduction-tutorials/tutorial-hello-world-spryker-commerce-os.html#build-the-helloworld-module

    In Yves it works a little bit different as you need to register the route in the Router module by creating a Router plugin.

    Also, the way themes work is different from the backoffice. You can go deeper into Yves, by following Frontend for backend developers course.
    In that course you´ll learn also how to override views, create widgets to include in different pages

  • harry
    harry Posts: 9 🧑🏻‍🚀 - Cadet
    edited January 29

    @sunil

    the home page is loading from controller

    \SprykerShop\Yves\HomePage\Controller\IndexController::indexAction

    You can print the data of "hello world" module in the home page corner but it's not simple.

    you need pass "hello world"data at the zed business layer and throw it into the facade instead.

    also you need declare provider in the "home page" module, take it according the communication factory layer and you can load "hello world" data at "hello world" controller.