Jump to content

Can't echo out page title (="$") on frontend


hellomoto
 Share

Recommended Posts

I have a price_currency field that references child pages of a page Currency. Its names are three-letter currency codes, and the titles are symbols: $, euro and pound. I tried inputting both $ and $ as the title instead for $ to see if it would echo; it's not. How can I get these values to appear?

$item->price_currency outputs the ID, but $item->price_currency->name doesn't even work either...

Link to comment
Share on other sites

you should maybe reference the name which is already the 3 letter code;

the title also can be the same uppercase code;

where you are echoing you could use a function to convert to the right entity

function get_cur_symbol($price,$cur) {
    $symbol = '';

    switch($cur) {
        case 'USD': return '$'.$price;   break;
        case 'AUD': return 'AU$'.$price;   break;
        case 'CAD': return 'CA$'.$price;   break;
        case 'GBP': return '£'.$price;   break;
        case 'JPY': return '¥'.$price;   break;
        case 'EUR': return '€'.$price;  break;
        case 'CHF': return 'C'.$price;   break;
        case 'CZK': return 'K'.$price;   break;
        case 'DKK': return 'k'.$price;   break;
        case 'HKD': return '圓'.$price; break;
        case 'HUF': return 'F'.$price;   break;
        case 'SGD': return 'S$'.$price;   break;
        case 'NOK': return 'k'.$price;   break;
        case 'NZD': return '$'.$price;   break;
        case 'PLN': return 'z'.$price;   break;
        case 'SEK': return 'k'.$price;   break;
    }
}
  • Like 1
Link to comment
Share on other sites

I have a price_currency field that references child pages of a page Currency. Its names are three-letter currency codes, and the titles are symbols: $, euro and pound. I tried inputting both $ and $ as the title instead for $ to see if it would echo; it's not. How can I get these values to appear?

$item->price_currency outputs the ID, but $item->price_currency->name doesn't even work either...

$item->price_currency returns page id like it should. $item->price_currency->title should give you what you are after.

If these don't work, then make sure you have single page reference for the field price_currency. If this $item->price_currency->first()->title works, then your field returns multiple pages (PageArray).

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...