How can we print data coming from controller in homepage?
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
-
Hi Sunil,
Here is an example in the docs.
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 pages0 -
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.
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random