1

I'm hugely grateful for a resource like stackexchange and the really useful posts. I've researched the problem I'm having for a couple of days now and am seriously stuck - so any help is massively appreciated!

I'm using the fpdf to work with a very customised favourites system (uses playa and matrix to have parent and child pages) within EE to generate a pdf of the favourited pages.

I have it working so that i can output the html required for the pdf but I need to get the entire output into a single variable to feed the pdf plugin. I tried using stash append and also stash with php and within an embed but it's not working as expected.

Everything is working except being able to append to a single variable and it being set properly. Within 'output_pdf' below I have set up a blank stash variable and I want to build up with barrister details within the pdf_format_barrister include. It's not working as expected though and the stash call with output="no" in doesn't seem to work at all and is still outputting the code.

I'm not sure how clear I'm being about what I'm tring to achieve but any pointers in retaining a variable and appending it across embeds is what I need really.

output_pdf (using php and php set to output):

// setup a blank stash variable to contain the output for the pdf to be appended in the embdeds
echo '{exp:stash:set name="pdf_string" output="no" parse_tags="yes" trim="yes" save="yes" replace="yes" scope="user"}{/exp:stash:set}';

// THE LOOP
$i = 0;
$num_barristers = sizeof($barrister_person_ids);

while ($i < $num_barristers) 
{
    $this_barrister_id = $barrister_person_ids[$i];

        //echo $this_barrister_id."<br/>";


        echo "{embed='includes/pdf_format_barrister' barrister_id='$this_barrister_id'}";



            $j=0;
            while ($j < $num_barrister_faves) { 

                //echo "<p>".$barrister_exploded_fave_ids[$j]."</p>";

                echo "{embed='includes/pdf_format_expertise' barrister_id='$this_barrister_id' fave_id='$barrister_exploded_fave_ids[$j]'}";

            $j++;
            }


    $i++;

}

$everything = '{exp:stash:get name="pdf_string"}';

pdf_format_barrister:

{exp:channel:entries dynamic="off" entry_id="{embed:barrister_id}" status="open" disable="pagination" limit="1" channel="barristers_jc|barristers_qc"}


    {exp:stash:set name="pdf_string" output="no" parse_tags="yes" trim="yes" save="yes" replace="yes" scope="user"}
    {exp:stash:get name name="pdf_string" scope="user"}  

            <br />
            <div id="pdf-practice-areas"  style="width: 100%; float: left;"> <!-- profile related practice for pdf -->

            <div style="width: 25%; float: right; text-align: right; margin-top: 15px;">
                <img src="{barristers_profile_image}" alt="{title}" title="{title}">
            </div>
            <div style="width: 74%; float: left;">
                <h1 style="display: inline-block;">{title}</h1>
                <br />
                <p>
                {if barristers_year_of_silk}jjYear of Silk: {barristers_year_of_silk format="%Y"}<br />{/if}
                Year of Call: {barristers_year_of_call format="%Y"}<br />
                {if barristers_email!="" OR clerks_email!=""}<a href="{if barristers_email}{barristers_email}{if:else}{clerks_email}{/if}">{if barristers_email}{barristers_email}{if:else}{clerks_email}{/if}</a><br />{/if}
                {if barristers_direct_dial}Direct Dial: {barristers_direct_dial}{/if}
                </p>


            </div>
            {if barristers_featured_quote}
                      <blockquote class="featured-quote" style="width: 50%; clear: both;">
                    {barristers_featured_quote}
                        {quote}
                        {if author_year}<h4>- Chambers &amp; Partners 2012</h4>{/if}
                    {/barristers_featured_quote}
                      </blockquote>
                {/if}
            <h2 class="header" style="clear: both;">Overview</h2>
            {barristers_profile_overview}

            {if barristers_other_quotes}<h2 class="header">Quotes</h2>{/if}
             {barristers_other_quotes sort="asc"}
             <blockquote>
                 {quote}
                 {if author_year}<h4>- {author_year}</h4>{/if}
              </blockquote>
            {/barristers_other_quotes}
            </div>

    {/exp:stash:set}

{/exp:channel:entries}

Thankyou very much in advance for any help!

Cheers,

Alex.

1
  • I tried and tried to understand your code, but I couldn't. Can you, please, fix the code block? Some explanation about the PDF plugin is good too.
    – Sobral
    Jun 10 '13 at 22:02
1

Just to echo Rob above it would help to fix your code block formatting above to make it more comprehensible, and add comments to explain what you are doing at each step.

I can see a few things in any case that might be a problem.

This recursion is likely to cause problems:

{exp:stash:set name="pdf_string" output="no" parse_tags="yes" trim="yes" save="yes" replace="yes" scope="user"}
{exp:stash:get name name="pdf_string" scope="user"}
{/exp:stash:set}

Putting embeds in a loop is bad for performance, because each embed creates a new instance of the template parser:

$j=0;
while ($j < $num_barrister_faves) { 

    //echo "<p>".$barrister_exploded_fave_ids[$j]."</p>";

    echo "{embed='includes/pdf_format_expertise' barrister_id='$this_barrister_id' fave_id='$barrister_exploded_fave_ids[$j]'}";

$j++;
}

Mixing PHP and ExpressionEngine tags is, in my opinion, always a bad idea. Besides the basic legibility of your code, EE tags are parsed recursively while PHP is parsed linearly. Confusion is practically guaranteed. It will be more performant and maintainable to write a custom module or plugin to handle the logic and use either the tagdata as the view or load a view to layout your output. Note that you can use Stash programatically if you want to set placeholders or reuse variables elsewhere, e.g. stash::set($params), stash::get($params)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.