We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18373 ☆ A M B ☆
    • 3,141 Posts
    Hello,

    I’m using NewsPublisher to create blog entries on my website. I’ve got three questions regarding that:

    1) I want to add another form where a link can be entered for a source, or link to a forum where it can be discussed. I’m guessing this can be done by a javascript? Or editing the php code of the snippet? I’m really new to programming/scripting like that.

    2) When I create a new blog item using NewsPublisher, and I have enters in the content (Like, who wouldn’t?), and I publish it, it removes all the spaces making it one paragraph.

    3) When I create a new blog item, it makes the new document, and shows it... but it doesn’t appear on the main page where it should list a summary of all blogs?
    EDIT: When I go into the Manager, and publish the document (so the post inside the folder) it does appear on the mainpage... is this merely cause I didn’t set a publish date?

    I figured the chunks I’m using might be convenient in showing me what I’m doing wrong:
    Chunk Publisher:
    [!NewsPublisher? &folder=`1`  &makefolder=`1`!]


    Chunk BlogTemplate:
    <h3>
    	<a href="[~[+id+]~]" title="[+title+]">[+title+]</a>
    </h3> <!-- link to blogs article with it's title (link is title) -->
     
    By <strong>[+author+]</strong> on [+date+]. <br />
    [+summary+]
    <br />
    <strong>[+link+]</strong>


    My Ditto call in the doc’s content:
    [!Ditto? &parents=`1` &summarize=`5` &total=`20` &tpl=`BlogTemplate` &extenders=`summary`!]


    So.. any ideas on how to fix this?
      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • 36592
      • 970 Posts
      Regarding 3), you should add &clearcache=`1` in your NewsPublisher call.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        #1, you will need to customize the snippet, both to have the desired fields in the form and to process the POST values from those fields on return.

        #2, I haven’t used this for a long time, so I’m not sure how content is entered (i.e. a plain textarea or a Rich Text editor), however, plain HTML (as in a plain textarea) does not recognize standard line returns, you need to explicitly use <p> tags, or
        tags for line breaks. And how a Rich Text Editor deals with line breaks depends on how it’s configured.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Thanks tkfm, that did the trick! laugh

          Thanks Susan aswell, it gave me a place to start from. Seeing as this is my first ’experience’ with PHP, could you, or somebody else, guide me a bit in customizing the snippet? From looking at it... instead of modifying the snippet to add the form (see code quoted below) wouldn’t a &formtpl=`chunkname` be sufficient to add the form?

          I’m also guessing getting the snippet to post it will be the hardest part for a newby like me... This is what I can find in the snippet to posting the new article
                      // post news content
                      $flds = array(
                          'pagetitle'     => $title,
                          'longtitle'     => $longtitle,
                          'description' => $description,
                          'introtext'     => $introtext,
                          'alias'             => $alias,
                          'parent'            => $folder, 
                          'createdon'     => $createdon,
                          'createdby'     => ($userid>0 ? $userid * -1:0),
                          'editedon'        => '0',
                          'editedby'        => '0',
                          'published'     => $published,
                          'pub_date'        => $pub_date,
                          'unpub_date'    => $unpub_date,
                          'deleted'         => '0',
                          'hidemenu'        => $hidemenu,
                          'menuindex'     => $mnuidx,
                          'template'        => $template,
                          'content'         => mysql_escape_string($header.$content.$footer)
                      );
                      $redirectid = $modx->db->insert($flds,$modx->getFullTableName('site_content'));

          Those fieldnames remind me of the info shown in the manager for each document, so I’m guessing that’s what it saving it to. Now the content is being posted.. well.. where exactly?
          It may be a lot of questions, but if you could point me into the right direction, or perhaps link me to a tutorial that would be an awesome help!

          As for the line-breaks, one of my friends also came up with the
          or <p> suggestion, that seems to work but I’ll probably add a RTE instead as that’s easier to use for some people. According to the snippet’s help file/documentation and this tutorial adding &rtcontent to the call should work. But does it have to point at a template variable like the tutorial shows how to do it? Or could I put the code for a RTE in a chunk and add that in the call? (Is that even possible? tongue)

          Thanks for the support so far!


          Mark



          Snippet part for the template
          // get form template
          if(isset($formtpl)) $formTpl = $modx->getChunk($formtpl);
          if(empty($formTpl)) $formTpl = '
              <form name="NewsPublisher" method="post">
                  <input name="NewsPublisherForm" type="hidden" value="on" />
                  Page title:<br /><input name="pagetitle" type="text" size="40" value="[+pagetitle+]" /><br />
                  Long title:<br /><input name="longtitle" type="text" size="40" value="[+longtitle+]" /><br />
                  Description:<br /><input name="description" type="text" size="40" value="[+description+]" /><br />
                  Published date:<br /><input name="pub_date" type="text" value="[+pub_date+]" size="40" readonly="readonly" />
                  <a onClick="nwpub_cal1.popup();" onMouseover="window.status=\'Select date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/images/icons/cal.gif" width="16" height="16" border="0" alt="Select date" /></a>
                  <a onClick="document.NewsPublisher.pub_date.value=\'\'; return true;" onMouseover="window.status=\'Remove date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="Remove date"></a><br />
                  Unpublished date:<br /><input name="unpub_date" type="text" value="[+unpub_date+]" size="40" readonly="readonly" />
                  <a onClick="nwpub_cal2.popup();" onMouseover="window.status=\'Select date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/images/icons/cal.gif" width="16" height="16" border="0" alt="Select date" /></a>
                  <a onClick="document.NewsPublisher.unpub_date.value=\'\'; return true;" onMouseover="window.status=\'Remove date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="Remove date"></a><br />
                  Summary:<br /><textarea name="introtext" cols="50" rows="5">[+introtext+]</textarea><br />
                  Content:<br /><textarea name="content" cols="50" rows="8">[+content+]</textarea><br />
                  <input name="send" type="submit" value="Submit" />
              </form>
              <script language="JavaScript" src="manager/media/script/datefunctions.js"></script>
              <script type="text/javascript">
                  var elm_txt = {}; // dummy
                  var pub = document.forms["NewsPublisher"].elements["pub_date"];
                  var nwpub_cal1 = new calendar1(pub,elm_txt);
                  nwpub_cal1.path="[(base_url)]manager/media/";
                  nwpub_cal1.year_scroll = true;
                  nwpub_cal1.time_comp = true;	
          
                  var unpub = document.forms["NewsPublisher"].elements["unpub_date"];
                  var nwpub_cal2 = new calendar1(unpub,elm_txt);
                  nwpub_cal2.path="[(base_url)]manager/media/";
                  nwpub_cal2.year_scroll = true;
                  nwpub_cal2.time_comp = true;	
              </script>';
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.