Either PDF or PHP page

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 31, 2011   (RSS)

Re: [degreesnorth] Either PDF or PHP page

By Toledoh - March 31, 2011

I normally have a field called "link type" that is a radio button with options as "internal", "external", "file".

Then I do an few if statments;
<?php if ($record['link_type'] == 'internal'): ?> ...your code...
<?php elseif ($record['link_type'] == 'external'): ?> ...your code...
<?php elseif ($record['link_type'] == 'file'): ?> ...your code...
<?php endif ?>
<?php endforeach; ?>

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Either PDF or PHP page

By degreesnorth - March 31, 2011

Hi Tim
Thanks for your reply. I'm a bit stuck about the third option ('file'). Is that meant to open the pdf file? Could you clarify please.
Cheers
Carole

Re: [degreesnorth] Either PDF or PHP page

By Toledoh - March 31, 2011

Try this;
<?php if ($record['link_type'] == 'internal'): ?>
<a href="<?php echo $record['link_field'] ?>">Link within site as a text field</a>
<?php elseif ($record['link_type'] == 'external'): ?>
<a href="<?php echo $record['link_field'] ?>" target="_blank">Link outside of site as a text field</a>
<?php elseif ($record['link_type'] == 'details'): ?>
<a href="<?php echo $record['_link'] ?>">This links to your details page</a>
<?php elseif ($record['link_type'] == 'file'): ?>
<?php foreach ($record['file'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br />
<?php endif ?>
<?php endif ?>
<?php endforeach; ?>


Hope it helps!
Cheers,

Tim (toledoh.com.au)

Re: [degreesnorth] Either PDF or PHP page

By gkornbluth - March 31, 2011

Hi Carole,

If you're trying to differentiate between different file extensions and automatically publish the correct code for each, you can also try this kind of approach, excerpted from one of the recipes in my CMSB Cookbook http://www.thecmsbcookbook.com :
<?php foreach ($your_tableRecords as $record): ?> <?php foreach ($record['your_upload_field'] as $upload): ?>

<?php if ($upload['extension'] == 'pdf'): ?>

The pdf download code

<?php endforeach ?>
<?php else: ?>

Link to your detail page

<?php endif ?>
<?php endforeach ?>


Or, you could just test for the existence an upload in the pdf upload field. Something like:

<?PHP if ($your_field_nameRecord['uploads']): ?>

download link...

<?php else: ?>

Link to your detail page

<?php endif ?>


You'll have to play a bit with the exact code required, but I hope that gives you some ideas.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php