Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
Hey all, I'm sorry if this is a repeat question, but I just cannot seem to turn this corner. Here's the deal:

I am trying to write a JOBS page, jobs.php. I am using the non-executable TEMPLATE page, template-jobs.php, to house the editable items for jobs.

Within JOBS I'm trying to find a solution that would basiclaly do this:
-if a job exists, fill in the menu on the left column and fill in content in a right column
-else show one big content area that says "no jobs".

I can't figure out how to look for _any_ job post existing. I only have found how to find if a variable within a posting exists.

Here's some stripped down HTML for where I'm at now. In the JOBS HTML below, I've added HTML comments with notes of how I'd expect something to work.

---------------------------------------------------------------
TEMPLATE: template-jobs.php (this page seems just fine)
----------
Code: Select all
<?php require_once( 'admin-cms/cms.php' ); ?>
<cms:template title="Template - Jobs" clonable="1" executable="0">
   <cms:editable name="job_title" label="Job Title" type="text" />
   <cms:editable name="job_content" label="Job Content" type="nicedit" />
</cms:template>
<?php COUCH::invoke(); ?>


---------------------------------------------------------------
JOBS: jobs.php
----------
Code: Select all
<?php require_once( 'admin-cms/cms.php' ); ?>
<cms:template title="Jobs" />
<htm>...<body>...
   <!-- I expect to have an "if a job exists" logic here. -->
   <!-- if_is_page & page_exists seemed incorrect -->
   <ul class="job-sidebar">
      <cms:pages masterpage="template-jobs.php" orderby="publish_date" order="asc">
         <li><cms:show job_title /></li>
      </cms:pages>
   </ul>
   <div class="job-content">
      <cms:pages masterpage="template-jobs.php" orderby="publish_date" order="asc">
         <cms:if job_title>
            <h2><cms:show job_title /></h2>
         </cms:if>
         <cms:if job_content>
            <cms:show job_content />
         </cms:if>
      </cms:pages>
   </div>
   <!-- i expect to end the "if job exists" and to have an "else do this" statement -->
   <!-- I would add in the "else do this":
      <div class=content-no-job">Whatever I want to say here</div>
   -->
...</body></html>
<?php COUCH::invoke(); ?>



Any help would be so amazing. Thanks!
Hello and welcome @nathanakers :)

The 'cms:pages' tag (as also the search, comments, related_pages, reverse_related_pages and query tags) support a parameter named 'count_only'. Setting this parameter will make these tags simply return the count of the matching pages found instead of listing them as they normally do.

So, taking your code's example, the following snippet will simply output the number of jobs found -
Code: Select all
<cms:pages masterpage='template-jobs.php' count_only='1' />

We can use this to set up a conditional as follows -
Code: Select all
<cms:set jobs_count="<cms:pages masterpage='template-jobs.php' count_only='1' />" />

<cms:if jobs_count >
    .. Your normal sidebar/content listing here ..
<cms:else />
    .. Message 'No Jobs Exist' ..
</cms:if>

Hope this helps.

P.S.
By the way, instead of using two templates you could have easily done the same thing using just the 'jobs.php' template. Define the editable region in the template and then use only the 'home-view'
Code: Select all
<cms:if k_is_home >
   ... existing code here ..
</cms:if>

Since we'd not be using the page_view, the individual job pages will never get shown (which is what you are trying to do by using a separate non-executable template, aren't you?).

Anyways, there can be multiple ways of doing the same thing. So your chosen way is fine too.

Thanks.
KK, thanks!
That was really helpful to learn a bit more about how templates work. However, the problem at hand ... I know I'm implementing it wrong, but this is what I thought you meant. (And, yes, you assumed rightly that I don't care to link into specific Jobs as job pages themselves.)

When you say
Code: Select all
<cms:if k_is_home >
   ... existing code here ..
</cms:if>


I expect that to mean:
Code: Select all
<body>
<cms:template title="Career Openings" clonable="1" executable="0">
    ... execuatable variables ...
</cms:template>

<cms:if k_is_home >
    <cms:pages masterpage="[this-current-page].php" orderby="publish_date" order="asc">
        ... sidebar/content ..
    </cms:pages>
<cms:else />
    ... No Jobs Exist ...
</cms:if>
</body>

But it doesn't work that way. How do I show/hide the sections depending on if jobs exist?

Thanks!
Hi,

They were actually two different things that I mentioned in my post. As it happened, you confused the two together :)

See, forget the k_is_home thing. Continue using the two template approach you have.
Now in the 'jobs.php' template (where you'll be listing the jobs from the other non-executable template), place the following -
Code: Select all
<cms:set jobs_count="<cms:pages masterpage='template-jobs.php' count_only='1' />" />

<cms:if jobs_count >
    .. Your normal sidebar/content listing here ..
<cms:else />
    .. Message 'No Jobs Exist' ..
</cms:if>

I've explained this bit of code in my original post (place your existing sidebar/content code in the specified place).
Using this you can know if there is any job at all to show.

Hope this helps.
Cool. Thanks. Yeah, I'm not sure I confused them as much as I just don't understand how k_is_home is used to distinguish if there's available content or not. I would write as little of pages as necessary though, so learning the k_is_home simple way of doing what I'm wanting would be awesome. If you don't mind ... I guess the big question is, where does the "no jobs content" live, and how is it called?

is it implemented like this?
Code: Select all
<cms:if k_is_home>
    <body> ... </body>
</cms:if>


or:
Code: Select all
<body>
<cms:if k_is_home>
    <cms:template> .../>
    <cms:pages> ... />
</cms:if>
</body>


or ...

Code: Select all
<body>
<cms:template> .../>
<cms:if k_is_home>
    <cms:pages> ... />
</cms:if>
</body>


or ... etc

Thanks! Sorry, just trying to learn here :)
'k_is_home' is *not* relevant to the problem at hand - which is to find if there is content or not and display accordingly. So, please let us lake it out of the equation for the time being :)

Following is a modified version of the code you posted. Please place it in jobs.php and let me know if this does what you want.
---------------------------------------------------------------
JOBS: jobs.php
----------
Code: Select all
<?php require_once( 'admin-cms/cms.php' ); ?>
<cms:template title="Jobs" />
<htm>...<body>...

    <cms:set jobs_count="<cms:pages masterpage='template-jobs.php' count_only='1' />" />

    <cms:if jobs_count >
        <ul class="job-sidebar">
          <cms:pages masterpage="template-jobs.php" orderby="publish_date" order="asc">
             <li><cms:show job_title /></li>
          </cms:pages>
       </ul>
       <div class="job-content">
          <cms:pages masterpage="template-jobs.php" orderby="publish_date" order="asc">
             <cms:if job_title>
                <h2><cms:show job_title /></h2>
             </cms:if>
             <cms:if job_content>
                <cms:show job_content />
             </cms:if>
          </cms:pages>
       </div>
    <cms:else />
        <!-- no jobs -->
        <div class=content-no-job">Whatever I want to say here</div>
    </cms:if>

...</body></html>
<?php COUCH::invoke(); ?>

Thanks.
6 posts Page 1 of 1