如何在StandaloneView中渲染INT_SCRIPT?

问题描述 投票:0回答:2

我正在使用 cObject ViewHelper 在独立视图中渲染 TypoScript 对象。该 TS 对象当前从其他页面获取 tt_content。但结果有 INT_SCRIPT 标记,而不是真正的内容。

这是我关于如何制作独立视图、模板和 TypoScript 的代码:

内部控制器:

public function renderStandaloneView($template = 'View/Show', $variables = array(), $fileExt = 'html', $noCache = TRUE) {
    if ( $noCache === TRUE ) $GLOBALS['TSFE']->set_no_cache();

    // Get standalone view
    $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
    $view          = $this->objectManager->get(StandaloneView::class);

    $view->getRequest()->setControllerExtensionName($this->extensionName);
    $view->setFormat($fileExt);
    $view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
    $view->setPartialRootPaths($configuration['view']['partialRootPaths']);
    $view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
    $view->setTemplate($template);

    // Render view
    $view->assignMultiple($variables);

    return $view->render();
}

打字脚本:

lib.myContent = COA
lib.myContent {
  10 = CONTENT
  10 {
    table = tt_content

    select {
        orderBy         = sorting
        where           = 0
        where.wrap      = colPos=|
        pidInList.field = uid
    }
  }
}

流体:

<f:for each="{myvars}" as="myvar" iteration="it">
  <f:cObject typoscriptObjectPath="lib.myContent" data="{uid:'{myvar.uid}'}" />
</f:for>

我无法更改要缓存的页面上所有未缓存的元素(例如内容元素/插件)。

那么我如何解析包括非缓存内容的独立视图而不插入 INT_SCRIPT 标记?

谢谢你的一切!

typo3 fluid extbase typo3-7.6.x typo3-extensions
2个回答
0
投票

找到解决方案。也许这不是解决该问题的最佳方法。但目前效果还不错。

public function renderStandaloneView($template = 'View/Show', $variables = array(), $fileExt = 'html') {
    // Get standalone view
    $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
    $view          = $this->objectManager->get(StandaloneView::class);

    $view->getRequest()->setControllerExtensionName($this->extensionName);
    $view->setFormat($fileExt);
    $view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
    $view->setPartialRootPaths($configuration['view']['partialRootPaths']);
    $view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
    $view->setTemplate($template);

    // Render view
    $view->assignMultiple($variables);

    // Handle the INT_SCRIPT markers
    $content = $view->render();
    $contentBak = $GLOBALS['TSFE']->content;
    $GLOBALS['TSFE']->content = $content;
    $GLOBALS['TSFE']->INTincScript();
    $content = $GLOBALS['TSFE']->content;
    $GLOBALS['TSFE']->content = $contentBak;
    unset($contentBak);

    return $content;
}

供您参考。我需要它来处理页面中的内容并通过邮件发送它们或使用外部工具渲染 pdf。但某些内容或页面仅适用于当前用户(不适用于组或其他用户)。我不想在控制器内或其他地方登录该用户。我认为这是处理这个问题的最佳情况。

仍然欢迎其他解决方案:-)


0
投票

当您从多个页面渲染内容时,我建议执行适当的子请求并使用自定义 PAGE 对象进行渲染。

以下 TypoScript 设置渲染页面的内容,但没有整个周围的标记(html、body、head 等)。

pageOnlyContent = PAGE
pageOnlyContent {
  typeNum = 123456
  
  config.disableAllHeaderCode = 1
  config.index_enable = 0
  
  1 = CONTENT
  1.table = tt_content
  1.select {
    where = {#colPos}=0
    orderBy = sorting
  }
}

接下来您需要一个执行子请求的 ViewHelper。

// ...
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Typolink\PageLinkBuilder;
// ...
class GetPageContentViewHelper extends AbstractViewHelper {
  use CompileWithRenderStatic;
  protected $escapeOutput = false;
  public function initializeArguments() {
    $this->registerArgument('pageUid', 'int', 'The page to render');
  }
  public function renderStatic($arguments, ...) {
    $pageLinkBuilder = GeneralUtility::makeInstance(PageLinkBuilder::class);
    $linkDetails = [
      'pageuid' => $arguments['pageUid'],
      'pagetype' => 123456
    ];
    [$url, $linkText, $target] = $pageLinkBuilder->build($linkDetails, '', '', ['forceAbsoluteUrl' => 1]);
    return GeneralUtility::getUrl($url);
  }
}

您的 Fluid 模板就会变成类似的东西

<f:for each="{myvars}" as="myvar" iteration="it">
  <mynamespace:getPageContent pageUid="{myvar.uid}" />
</f:for>

(这是按原样编写的,未经尝试,请告诉我它是否有效。)

© www.soinside.com 2019 - 2024. All rights reserved.