0

I am working on an Expressionengine site at the moment, the client would like the ability to choose if there's a custom phone number in the sidebar of the page and if non is entered it just shows the default GV phone number. I have added the channel fields to each page and written a conditional statement but can't get it to work. My statement looks like this;

  {if get_in_touch_jobs_phone}
    <p>{get_in_touch_jobs_phone}</p>

  {if:elseif get_in_touch_media_phone}
    <p>{get_in_touch_media_phone}</p>

  {if:elseif get_in_touch_pages_phone}
    <p>{get_in_touch_pages_phone}</p>

  {if:elseif get_in_touch_staff_phone}
    <p>{get_in_touch_staff_phone}</p>

  {if:elseif get_in_touch_volunteering_phone}
    <p>{get_in_touch_volunteering_phone}</p>

  {if:else}
    <p>{gv-global-telephone}</p>
  {/if}

I'm trying to make the statement go through each pages custom phone field and check if it is there, if not it should move to the next statement and check if anything's there until it reaches the 'catch-all' else of using the global phone number.

For some reason this code always outputs the global phone number even if the custom phone field has been filled out, so I presume my elseif's syntax is not quite right, could anybody give me some advice/pointers as what I can do to get this working?

EDIT: I have now got this code which is working much closer to what I am looking for.

Certain pages won't take the custom numbers entered and will just show the global number even if there is a custom number set on a page, here is the code at the moment;

  {exp:channel:entries limit="1"}

      {if get_in_touch_jobs_phone}
        <p>{get_in_touch_jobs_phone}<br />

      {if:elseif get_in_touch_media_phone}
        <p>{get_in_touch_media_phone}<br />

      {if:elseif get_in_touch_pages_phone}
        <p>{get_in_touch_pages_phone}<br />

      {if:elseif get_in_touch_staff_phone}
        <p>{get_in_touch_staff_phone}<br />

      {if:elseif get_in_touch_volunteering_phone}
        <p>{get_in_touch_volunteering_phone}<br />

      {if:else}
        <p>{gv-global-telephone}<br />      
      {/if}

  {/exp:channel:entries}
  • how are you populating the other phone number tags?? i.e. get_in_touch_jobs_phone?? Also, are you within a channel entries loop? Can you include the entries tag your using and let us know exactly how you are entering the other phone numbers (are they fields on an entry in a channel??? – Blatant May 11 '15 at 11:26
  • They are being populated by the page entries in the channels, for example on an a job listing page there is a channel field called get in touch jobs phone number which can be filled in and shown on the sidebar instead of the global one. – Harry Francis May 11 '15 at 11:28
  • I have just added the entries tag {exp:channel:entries channel="{my_channel}" limit="1"} which has fixed it displaying on some pages, but on other pages it shows nothing. – Harry Francis May 11 '15 at 11:29
  • Have you added in an {entry_id} or {title} in your channel entries loop to make sure you're looking at the expected entry? – Romans-8---31-39 May 11 '15 at 13:43
  • I'm trying to get all entries through so I don't think limiting it would help, it looks like the key pages aren't coming though for some reason, do you know what could be causing that? – Harry Francis May 11 '15 at 13:48
0

Can yuo try this thought experiment, it's a bit of a 'shot in the dark' but before when I've fought with advanced conditionals this might get you out of jail...

  {if "{get_in_touch_jobs_phone}" != ""}
    <p>{get_in_touch_jobs_phone}<br />

  {if:elseif "{get_in_touch_media_phone}" != ""}
    <p>{get_in_touch_media_phone}<br />

  {if:elseif "{get_in_touch_pages_phone}" != ""}
    <p>{get_in_touch_pages_phone}<br />

  {if:elseif "{get_in_touch_staff_phone}" != ""}
    <p>{get_in_touch_staff_phone}<br />

  {if:elseif "{get_in_touch_volunteering_phone}" != ""}
    <p>{get_in_touch_volunteering_phone}<br />

  {if:else}
    <p>{gv-global-telephone}<br />      
  {/if}

The theory being {if fieldname} could just be referrign to "If the field / value exists" kind of like isset, whereas adding the quotes and squiggly braces {if "{fieldname}" != ""} parses the value into a string, the advanced conditional is then a string match...

like I say, bit of a shot in the dark however you are on an older EE so this might still be relivent (from my memory EE2.10.1 had some jiggery pokery around advanced conditionals, EE2.9.3 bug (#20621) link)

|improve this answer|||||
  • Hey! I have managed to get the conditional working now, I didn't have a channel entries loop around them which was stopping the variables working. The issue now is key pages (I'm not sure their real name, its like /jobs/job would be the single page and the key page is /jobs where the single pages are linked from), aren't working with the conditionals, I think this is something to do with my channel entries loop. Thanks for you're answer though! – Harry Francis May 11 '15 at 15:34
  • Is the code example in your OP exactly what you have on the jobs page?? Ever way, please let us know your channel label and I'll post a new answer, tested in my sandbox with the fields you state... – Blatant May 11 '15 at 15:39
  • Also, are you still displaying the number in your 'sideabar' on the jobs page? If so then think, if you are displaying say 50 jobs on the jobs page, what number do you want inthe sidebar?? the staff number from entry 23, the pages number from entry 5?? Or are you just trying to display the relivent number on the row in question?? – Blatant May 11 '15 at 15:42
  • Finally, once you have it all working (individual and listing pages) please do mark the answer (if supplied), if your answer isn;t on this page (perhaps its in comments) at least please take the time to Write Your Own Answer and mark as the answer, it helps everyone else! – Blatant May 11 '15 at 15:49
0

AS the question has moved onto a display issue on the listing page, I've supplied another answer, firstly I'm guessing at the code, until the OP comes back to us.

Here we assume the channel is called "Jobs" (jobs)

{exp:channel:entries channel="jobs" dynamic="no"}

    <h1>Job Title : {title}</h1>

    <a href="/jobs/{url_title}" alt="more info...">more info...</a>

    <p>To enquire please phone : 
      {if get_in_touch_jobs_phone}
        {get_in_touch_jobs_phone}
      {if:elseif get_in_touch_media_phone}
        {get_in_touch_media_phone}
      {if:elseif get_in_touch_pages_phone}
        {get_in_touch_pages_phone}
      {if:elseif get_in_touch_staff_phone}
        {get_in_touch_staff_phone}
      {if:elseif get_in_touch_volunteering_phone}
        {get_in_touch_volunteering_phone}
      {if:else}
        {gv-global-telephone}     
      {/if}
    </p>

    <hr />

{/exp:channel:entries}
|improve this answer|||||

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.