2

I am using SafeCracker to create some entries on a site and when the form is submitted it comes up in a preview template.

I need to be able to display the selected category for the entry.

I am using the following code to display the results in the preview template:

{exp:safecracker channel="jobs" id="contact" return="jobs/preview/ENTRY_ID" entry_id="{segment_3}"}

<p>Job Type: {job_type}<br />
  Category: {exp:channel:category_heading}{category_name}{/exp:channel:category_heading}<br />  
  Location: {job_location}</p>
  <p>Description:<br />
  {job_description}
  </p>
  <p>Apply by: {how_to_apply} at: {apply_value}</p>
  <p>Company: {company}</p>
  <p>Description: <br />
  {company_description}</p>
{/exp:safecracker}

As it is, the Category: value is blank. What is the correct way to do this?

Thanks!

1 Answer 1

3

Use: {categories}{if selected}{category_name}{/if}{/categories}.

Failing that, you could use the query module:

{exp:query sql="
    SELECT c.cat_name
    FROM exp_categories c, exp_category_posts cp
    WHERE cp.entry_id = {segment_3}
    AND c.cat_id = cp.cat_id
" backspace="2"}{cat_name}, {/exp:query}
3
  • Hi Derek, I gave this a go and it works to a degree. It displays all the channel categories instead of the one that was selected. Is there something else I am missing? Thanks.
    – forrest
    Oct 18, 2012 at 17:54
  • Hi Derek, sorry for the delay - crazy weekend. I tried the modified code above and still don't get any value returned. Any other ideas?
    – forrest
    Oct 22, 2012 at 15:13
  • Hi Derek, that was perfect. Thanks for the patient assistance.
    – forrest
    Oct 23, 2012 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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