On this page:
3.1 Make the Functional Workflow Capture Content Like The Imperative Workflow
3.2 Make the Imperative Workflow Reformat Invalid Content
7.6

3 How-To: Include Module Instantiation Side-Effects As Content

In some cases you may need to capture output before incorporating it into the page.

3.1 Make the Functional Workflow Capture Content Like The Imperative Workflow

In The Functional Workflow, you can write an app element that, like in The Imperative Workflow, reads tagged X-expressions written by another module as a side-effect of instantiation:

"<script type="application/racket">...</script>"

#lang racket/base
 
(require polyglot racket/port)
(provide replace-page)
 
(define (replace-page page-tx)
  (tx-replace-me page-tx
                 (λ (x)
                   (define-values (i o) (make-pipe))
                   (parameterize ([current-output-port o])
                     (dynamic-require "loud-module.rkt" #f)
                     (close-output-port o))
                   (port->list read i))))

3.2 Make the Imperative Workflow Reformat Invalid Content

In The Imperative Workflow, app elements cannot display or print content if it would result in reading a value that is not a Tagged X-Expression.

You can use the same trick above to capture and reformat content:

"<script type="application/racket">...</script>"

#lang racket/base
 
(require racket/port)
 
(define-values (i o) (make-pipe))
(parameterize ([current-output-port o])
  (dynamic-require "displays-string.rkt" #f)
  (close-output-port o))
 
(write `(p ,(port->string i)))