XF 2.1 BBCode in Polls

Yodrak

in memoriam 1976 - 2020
Hello i try to extend the poll_macro template, so that i can use bbcode in Polls.

HTML:
<xf:macro name="vote" arg-poll="!">
    <div class="block-body">
        <div class="block-row">
            <xf:if is="$poll.max_votes == 1">
                <xf:radio name="responses[]">
                    <xf:foreach loop="$poll.responses" key="$responseId" value="$response">
                        <xf:option value="{$responseId}">{{ bb_code($response.response|censor|raw) }}
                        </xf:option>
                    </xf:foreach>
                </xf:radio>
            <xf:else />
                <xf:checkbox name="responses[]">
                    <xf:foreach loop="$poll.responses" key="$responseId" value="$response">
                        <xf:option value="{$responseId}">{$response.response|censor}</xf:option>
                    </xf:foreach>
                </xf:checkbox>
            </xf:if>
        </div>
        <xf:if contentcheck="true">
            <hr class="block-separator" />
            <div class="block-row block-row--minor">
                <ul class="listInline">
                <xf:contentcheck>
                    <xf:if is="$poll.close_date">
                        <xf:if is="!$poll.isClosed()">
                            <li>{{ phrase('this_poll_will_close:') }} <xf:date time="{$poll.close_date}" />.</li>
                        <xf:else />
                            <li>{{ phrase('poll_closed') }} <xf:date time="{$poll.close_date}" />.</li>
                        </xf:if>
                    </xf:if>
                    <xf:if is="$poll.max_votes != 1">
                        <li>{{ phrase('multiple_votes_allowed') }}</li>
                    </xf:if>
                    <xf:if is="$poll.public_votes">
                        <li>{{ phrase('your_vote_will_be_publicly_visible') }}</li>
                    </xf:if>
                </xf:contentcheck>
                </ul>
            </div>
        </xf:if>
    </div>
    <div class="block-footer">
        <span class="block-footer-controls">
            <xf:button type="submit" class="button--primary" icon="vote">{{ phrase('cast_vote') }}</xf:button>
            <xf:if is="$poll.canViewResults()">
                <xf:button href="{{ $poll.getLink('results') }}" overlay="true" icon="result" rel="nofollow">{{ phrase('view_results') }}</xf:button>
            </xf:if>
        </span>
    </div>
</xf:macro>

If i use this code:

HTML:
<xf:option value="{$responseId}">{{ bb_code($response.response|censor|raw) }}

It´s throws me a error

Code:
Server error log
ArgumentCountError: Too few arguments to function XF\Template\Templater::fnBbCode(), 3 passed and at least 5 expected src/XF/Template/Templater.php:2009
Generated by: Yodrak Dec 30, 2018 at 3:09 PM

Stack trace
#0 [internal function]: XF\Template\Templater->fnBbCode(Object(XF\Template\Templater), true, '[b]fett[/b]')
#1 src/XF/Template/Templater.php(914): call_user_func_array(Array, Array)
#2 internal_data/code_cache/templates/l1/s1/public/poll_macros.php(91): XF\Template\Templater->fn('bb_code', Array, true)
#3 src/XF/Template/Templater.php(693): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#4 internal_data/code_cache/templates/l1/s1/public/poll_macros.php(42): XF\Template\Templater->callMacro('poll_macros', 'vote', Array, Array)
#5 src/XF/Template/Templater.php(693): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#6 internal_data/code_cache/templates/l1/s1/public/thread_view.php(209): XF\Template\Templater->callMacro('poll_macros', 'poll_block', Array, Array)
#7 src/XF/Template/Templater.php(1293): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#8 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('thread_view', Array)
#9 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#10 src/XF/Mvc/Dispatcher.php(418): XF\Mvc\Renderer\Html->renderView('XF:Thread\\View', 'public:thread_v...', Array)
#11 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(360): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#13 src/XF/Mvc/Dispatcher.php(53): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#14 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()
#15 src/XF.php(392): XF\App->run()
#16 index.php(20): XF::runApp('XF\\Pub\\App')
#17 {main}

Request state
array(4) {
  ["url"] => string(33) "/index.php?threads/testthread.16/"
  ["referrer"] => string(72) "https://staging.thailand-asienforum.com/index.php?threads/testthread.16/"
  ["_GET"] => array(1) {
    ["threads/testthread_16/"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}

What is the proper way to use bbcodes in polls?
 
First, you don't need the |censor|raw filters here. The BB code parser will censor and the raw is implied in this context.

Look at how we render BB codes in posts as an example:
Code:
{{ bb_code($post.message, 'post', $post) }}

The first argument is the content to render. The second is a named context (which allows options per context); you'd probably want to use something like poll. The third argument is the content the BB code render relates to. This bit is fairly complex but it allows passing data and options to the BB code renderer; this probably isn't too significant for your usage, so you can probably just pass the poll itself.
 
First, you don't need the |censor|raw filters here. The BB code parser will censor and the raw is implied in this context.

Look at how we render BB codes in posts as an example:
Code:
{{ bb_code($post.message, 'post', $post) }}

The first argument is the content to render. The second is a named context (which allows options per context); you'd probably want to use something like poll. The third argument is the content the BB code render relates to. This bit is fairly complex but it allows passing data and options to the BB code renderer; this probably isn't too significant for your usage, so you can probably just pass the poll itself.
@Mike in this context does that mean I don't need to render bb_code in my own file as XenForo does it automatically as long as I provide the message data being rendered?
 
Changed the radio, check and result lines to {{ bb_code($response.response, 'poll', $poll) }} and seems to work (y)
 
Back
Top Bottom