• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 auto populate editor by forum

dethfire

Well-known member
#1
I'm trying to add a message to the create thread editor textarea depending on the forum, but this isn't working

<xen:if is="in_array({$thread.node_id}, array(154,154,155,156,157,158))">

test

</xen:if>

If I take the conditional out, test shows. Maybe this conditional doesn't work in create thread?
 

dethfire

Well-known member
#5
<xen:hook name="editor" params="{xen:array 'editorId={$editorId}'}">
<div>
<xen:if is="{$showWysiwyg}">
<textarea name="{$formCtrlNameHtml}" id="{$editorId}_html" class="textCtrl MessageEditor BbCodeWysiwygEditor {$editorOptions.extraClass}" style="display:none; {xen:if $height, 'height: {$height};'}" data-css-url="css.php?style={xen:urlencode $visitorStyle.style_id}&amp;css=editor_contents&amp;d={xen:urlencode $visitorStyle.last_modified_date}" data-dialog-url="index.php?editor/dialog&style={$visitorStyle.style_id}" {xen:if $editorOptions.autoSaveUrl, 'data-auto-save-url="{$editorOptions.autoSaveUrl}"'} {xen:if $editorOptions.json, 'data-options="{xen:escape {xen:helper json, $editorOptions.json}}"'}>{$messageHtml}

<xen:if is="{$forum.node_id} == 153">

test

</xen:if>
</textarea>
 

cclaerhout

Well-known member
#8
  1. Use the editor_setup listener
  2. Use the view to get its parameters:
    PHP:
      $viewParams = $view->getParams();
       $nodeId = (isset($viewParams['forum'], $viewParams['forum']['node_id'])) ? $viewParams['forum']['node_id'] : null;
       $templateName = $view->getTemplateName();
  3. And try something like this:
    PHP:
      if($templateName == 'thread_create' && $nodeId)
       {
         switch($nodeId)
         {
           case '1':
             if($showWysiwyg)
             {
               $message = '<b>my message</b>';
             }
             else
             {
               $message = '[B]my message[/B]';   
             }
             break;
           case '2':
             if($showWysiwyg)
             {
               $message = '<b>my message 2</b>'
             }
             else
             {
               $message = '[B]my message 2[/B]';   
             }
             break;
         }
       }

P.S: I haven't tried.
 

Brogan

XenForo moderator
Staff member
#9
It wasn't clear you actually wanted the text in the editor window.

The node id isn't available in the editor template so you can't do that.