What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

It worked well, without passing data from indexcontroller to twig. Looks like passing data to twig f

2

Comments

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet
    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\HelloWorld\Plugin\Router;
    
    use Spryker\Yves\Router\Plugin\RouteProvider\AbstractRouteProviderPlugin;
    use Spryker\Yves\Router\Route\RouteCollection;
    
    class HelloWorldPageRouteProviderPlugin extends AbstractRouteProviderPlugin
    {
        protected const ROUTE_HELLO_WORLD_INDEX = 'hello-world-index';
    
        /**
         * Specification:
         * - Adds Routes to the RouteCollection.
         *
         * @api
         *
         * @param \Spryker\Yves\Router\Route\RouteCollection $routeCollection
         *
         * @return \Spryker\Yves\Router\Route\RouteCollection
         */
        public function addRoutes(RouteCollection $routeCollection): RouteCollection
        {
            $routeCollection = $this->addHelloWorldIndexRoute($routeCollection);
    
            return $routeCollection;
        }
    
        /**
         * @param \Spryker\Yves\Router\Route\RouteCollection $routeCollection
         *
         * @return \Spryker\Yves\Router\Route\RouteCollection
         */
        protected function addHelloWorldIndexRoute(RouteCollection $routeCollection): RouteCollection
        {
            $route = $this->buildRoute('/hello-world', 'HelloWorld', 'Index', 'indexAction');
            $routeCollection->add(static::ROUTE_HELLO_WORLD_INDEX, $route);
    
            return $routeCollection;
        }
    }
    
  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UPWG882P6 Another problem could be that you have to replace your twig file to another path

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    another path?

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    maybe the path to add the index.twig is not correct in the documentation

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2020

    I got nearly the same problem, and I remember that I changed the file to another path and then it worked, I try to find out where

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    where did u change the path to?

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    okay I didn’t saw the path you had put your index.twig into, seems to be right, Let me try to figure out on my demo shop, maybe I figure it out

  • Path in controller has to fit the real path in project

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay my example is working

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet
    return $this->view(
        $data,
        [],
        '@HelloWorld/views/index/index.twig'
    );
    
  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    its still not working

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    now I used your Provider Class and changed the name to the file name HelloWorldRouteProviderPlugin.php with class HelloWorldRouteProviderPlugin extends AbstractRouteProviderPlugin

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    maybe I share my stuff to you

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    ok

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    <?php
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\HelloWorld\Plugin\Router;
    
    use Spryker\Yves\Router\Plugin\RouteProvider\AbstractRouteProviderPlugin;
    use Spryker\Yves\Router\Route\RouteCollection;
    
    class HelloWorldRouteProviderPlugin extends AbstractRouteProviderPlugin
    {
        protected const ROUTE_HELLO_WORLD_INDEX = 'hello-world-index';
    
        /**
         * Specification:
         * - Adds Routes to the RouteCollection.
         *
         * @param RouteCollection $routeCollection
         *
         * @return RouteCollection
         * @api
         *
         */
        public function addRoutes(RouteCollection $routeCollection): RouteCollection
        {
            $routeCollection = $this->addHelloWorldIndexRoute($routeCollection);
            return $routeCollection;
        }
    
        /**
         * @param RouteCollection $routeCollection
         *
         * @return RouteCollection
         */
        protected function addHelloWorldIndexRoute(RouteCollection $routeCollection): RouteCollection
        {
            $route = $this->buildRoute('/hello-world-test', 'HelloWorld', 'Index', 'indexAction');
            $routeCollection->add(static::ROUTE_HELLO_WORLD_INDEX, $route);
            return $routeCollection;
        }
    }
    
  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2020

    Registered in src/Pyz/Yves/Router/RouterDependencyProvider.php like this: `

    namespace Pyz\Yves\Router;
    
    use Pyz\Yves\ExampleProductSalePage\Plugin\Router\ExampleProductSaleRouteProviderPlugin;
    use Pyz\Yves\HelloWorld\Plugin\Router\HelloWorldRouteProviderPlugin;
    
    ...
    
    protected function getRouteProvider(): array
        {
            return [
                new ErrorPageRouteProviderPlugin(),
                new HomePageRouteProviderPlugin(),
                new CheckoutPageRouteProviderPlugin(),
                ...
    // here comes our plugin
                new HelloWorldRouteProviderPlugin(),
            ]; 
       }
    
  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    the Controller IndexController.php:

    <?php
    
    namespace Pyz\Yves\HelloWorld\Controller;
    
    use Spryker\Yves\Kernel\Controller\AbstractController;
    use Spryker\Yves\Kernel\View\View;
    use Symfony\Component\HttpFoundation\Request;
    
    class IndexController extends AbstractController
    {
        /**
         * @param Request $request
         *
         * @return View
         */
        public function indexAction(Request $request)
        {
            $data = ['helloWorld' => 'Hello Worldklljkl!'];
    
            return $this->view(
                $data,
                [],
                '@HelloWorld/views/index/index.twig'
            );
        }
    }
    
  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    and the twig file index.twig :

    {% extends template('page-layout-main') %}
    
        {% define data = {
            helloWorld: _view.helloWorld
        } %}
    
        {% block content %}
            <div><h2>{{ data.helloWorld }}</h2></div>
        {% endblock %}
    
  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    and executed:

    $ docker/sdk cli npm run yves:watch
    # and in a second terminal tap
    $ docker/sdk console cache:empty-all
    
  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    Am using vagrant

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2020

    should not be that different

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    in your vagrant box I think it is possible to run npm run yves:watch

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2020

    I think you just have file name <-> class name differences which cause in that issue, but you can’t see it because you IDE doesn’t show you the misspelling (sniffers) or your vagrant box is caching all things as hell πŸ‘Ώ

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    but I’m not that backend expert ^^

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    I corrected the filename

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    also replaced with your code, still the same

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet

    and the file name is the same like you named your class ?

  • UPWG882P6
    UPWG882P6 Posts: 140 πŸ§‘πŸ»β€πŸš€ - Cadet

    yes

  • U01AM1YGRC2
    U01AM1YGRC2 Posts: 71 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2020

    Okay, then let us check:
    β€’ file names for controller and plugin are the same like class names?
    β€’ the plugin is used and added to src/Pyz/Yves/Router/RouterDependencyProvider.php correctly?
    β€’ you emptyed the caches?
    β€’ you called the new address: http://yves.de.spryker.local/hello-world-test ?
    β€’ -> I changed the /hello-world to /hello-world-test now at /hello-world should be a 404 Page not found