sulu - 如何通过 twig 模板或 twig 扩展中的 url 获取页面内容?
问题描述
所以有 twig 函数sulu_content_load('1234-1234')
可以通过uuid
. 有没有办法通过 url 获取页面内容,比如/team/member-1
or /about-us
?
解决方案
目前没有为此的树枝扩展 - 但您可以编写自己的并使用以下服务:
- "sulu.content.resource_locator.strategy_pool" 通过您的 webspace 密钥获取资源定位器策略
$resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey("my-webspace-key");
- 获取页面的uuid
$uuid = $resourceLocatorStrategy->loadByResourceLocator("/test-1", "my-webspace-key", "de");
- 使用“sulu_document_manager.document_manager”获取页面文档
$document = $documentManager->find($uuid, "de");
在此之后的问题是你想用这个文件做什么?您需要内容中的一些信息吗?或者也许是别的什么?
推荐阅读
- php - 类别/产品页面上的 Magento 1.9 sql 注入
- c# - 使用 JsonConvert.DeserializeObject 反序列化 yyyyMMddTHHmmssZ DateTime 格式
- ios - 第一个元素标记空列表字符串。崩溃仅在生产中发生
- javascript - 将自定义 javascript 文件导出到 Vue 组件
- opencv - 使用opencv检测棋盘上方的手
- node.js - CosmosDB + MongoAPI,更新文档解决方法?
- c++ - Linux 共享内存 - shmget 失败
- python - 在任何地方将 Django 应用程序上传到 Python
- android - 如何在 Kotlin 中声明静态变量和方法?
- sql - 无法在 SQL Server 中运行 .sql 文件