Forum

Thread tagged as: Question

Using Document Assets in story content region

We want to build a library of standard definitions or explanations that editors can select from and drop into their work.

I assume this functionality can be provided in Assets? Correct?

I am able to create small documents and load them into Assets OK. I assume I define them as .txt. Correct?

What I haven't been able to figure out is how to then select one to add to a story I am writing.

I am reasonably familiar with using Assets, but so far only with images. We regularly select an image in Assets and add it to a content region defined as follows:

<img src="<perch:content type="image" id="image" label="Image" width="200px" height="200px" quality="85"/>" alt="<perch:content type="text" id="alt" label="Description" required="true" help="Put Pilot or Squadron Badge here" title="true" />" />

We want to do the equivalent with document Assets and drop them into a story content region currently defined as follows:

<perch:content id="text" type="textarea" label="Text" editor="redactor" html="true" imagewidth="760" before="This is the main story area" />

What changes do I have to make to my story content region to allow me to select a text Asset and drop it into the story I am writing?

Thanks in advance

Stefan Youngs

Stefan Youngs 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What result are you trying to achieve? Assets manages images (embedded) and files (linked).

We want to build a library of standard definitions or explanations that editors can select from and drop into their work. This will save us writing the same boilerplate for each story. I had hoped Assets (Documents) would be usable in this way.

What is the difference between dropping a reusable image Asset into a region and dropping a chunk of reusuable text into a region? Can I do the latter with Assets, and if so, can you tell me how. Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's not something that Assets offers.

Ok thanks. Pity. It would be useful.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could always have someone build you an app to do that using the API.

Have you looked at the clips plugin from redactor? You can define a list of snippets that can be inserted in the editor.

You can download the plugin from Imperavi's plugins page.

Here's an example of the redactor _config.inc:

<script type="text/javascript" src="PERCH_LOGINPATH/addons/plugins/editors/redactor/redactor/redactor.min.js"></script>
<link rel="stylesheet" href="PERCH_LOGINPATH/addons/plugins/editors/redactor/perch/edit.css" type="text/css" />
<link rel="stylesheet" href="PERCH_LOGINPATH/addons/plugins/editors/redactor/redactor/redactor.css" type="text/css" />

<script type="text/javascript" src="PERCH_LOGINPATH/addons/plugins/editors/redactor/plugins/clips/clips.js"></script>
<link rel="stylesheet" href="PERCH_LOGINPATH/addons/plugins/editors/redactor/plugins/clips/clips.css" type="text/css" />

<script type="text/javascript" charset="utf-8"> 
$(function() {
    $('textarea.redactor').each(function(i,o){
        var self = $(o);
        self.wrap('<div class="editor-wrap" style="float:left;"></div>');
        self.redactor({
            minHeight: parseInt(self.css('height')) || 120,
            imageUpload: 'PERCH_LOGINPATH/addons/plugins/editors/redactor/perch/upload.php?filetype=image',
            fileUpload: 'PERCH_LOGINPATH/addons/plugins/editors/redactor/perch/upload.php',
            uploadFields: {
                'width'  :  self.attr('data-width')||'',
                'height' :  self.attr('data-height')||'',
                'crop'   :  self.attr('data-crop')||'',
                'quality':  self.attr('data-quality')||'',
                'sharpen':  self.attr('data-sharpen')||'',
                'density':  self.attr('data-density')||'',
                'bucket' :  self.attr('data-bucket')||'default'
            },
            plugins: ['clips']
        });
    });
});
</script> 

<div id="redactor-plugins" style="display: none;">

  <div id="clipsmodal" style="display: none;">
    <section>
    <!-- definitions -->
      <ul class="redactor_clips_box">
        <li>
          <a href="#" class="redactor_clip_link">Snippet title</a>
          <div class="redactor_clip" style="display: none;">
            Snippet content
          </div>
        </li>
      </ul>
      <!--/ definitions -->
    </section>
    <footer>
      <button class="redactor_modal_btn redactor_btn_modal_close">Close</button>
    </footer>
  </div>

</div>

Thanks so much. I tried but failed to get this working earlier. I'll follow your instructions and hopefully it will work. Thankyou for your help.