How to set noindex and nofollow metas in symfony framework?


by hanna , in category: SEO , 4 months ago

How to set noindex and nofollow metas in symfony framework?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by rusty.rosenbaum , 4 months ago


In Symfony framework, you can set the noindex and nofollow metas by following these steps:

  1. Create a new Twig template file in your project, for example, noindex.html.twig, and add the following content: {% block meta %} {% endblock %}
  2. In your controller, render this template and pass it to the response: use SymfonyBundleFrameworkBundleControllerAbstractController; use SymfonyComponentHttpFoundationResponse; class YourController extends AbstractController { public function yourAction(): Response { return $this->render('noindex.html.twig'); } }
  3. Customise your routes to use this controller and action. For example, in your routes.yaml file, define a new route: your_route: path: /your-path controller: AppControllerYourController::yourAction
  4. Finally, access the route /your-path in your browser, and the response will include the noindex and nofollow meta tags.

Note: The above example assumes you are using Twig as the template engine in your Symfony project. If you are using another template engine, adjust the template file and rendering syntax accordingly.