首页 > 解决方案 > 如何通过 twig 模板或 twig 扩展中的 url 获取页面内容?

问题描述

所以有 twig 函数sulu_content_load('1234-1234')可以通过uuid. 有没有办法通过 url 获取页面内容,比如/team/member-1or /about-us

标签: sulu

解决方案


目前没有为此的树枝扩展 - 但您可以编写自己的并使用以下服务:

  1. "sulu.content.resource_locator.strategy_pool" 通过您的 webspace 密钥获取资源定位器策略
$resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey("my-webspace-key");
  1. 获取页面的uuid
$uuid = $resourceLocatorStrategy->loadByResourceLocator("/test-1", "my-webspace-key", "de");
  1. 使用“sulu_document_manager.document_manager”获取页面文档
$document = $documentManager->find($uuid, "de");

在此之后的问题是你想用这个文件做什么?您需要内容中的一些信息吗?或者也许是别的什么?


推荐阅读