[Pro] Styling PHP

I have created some PHP content which will be displayed via a Markup item. The code works fine but I’m having a lot of trouble getting the formatting/style correct. It’s a news feed from a database and I want to have a heading (heading_style), story (body_style) and a ‘read more’ button (read_more_style).

To get the style tags I created a simple html item and styled things as I wanted. I then copied the styles into the echo command of my PHP and things worked for a while. I created some additional styles and somehow my PHP styles broke. No amount of tinkering has been able to get them working again.

A few questions.
Are styles reliable? I have done a few things which have behaved oddly and I’m not sure whether it’s my inexperience or whether they’re perhaps a bit fiddly.
Should I have a style applied to the Markup item if I want the styles to come from the PHP?
Will a Page style affect my Markup item?
Should the styles in the PHP override anything else which is set?

Any assistance or tips would be greatly appreciated. I’m having a great time experimenting with Freeway and this seems to be the last stumbling block as just about everything we do runs via PHP.

'k


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You can add styling info into the head of your FW page that should then be picked up in your PHP if it is named correctly.

Can you show us an online example so that we can see what styles are in there already.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On 30/03/2012, at 11:39 PM, DeltaDave wrote:

You can add styling info into the head of your FW page that should then be picked up in your PHP if it is named correctly.

Ah, this is the issue. I didn’t realise these styles had to be ‘declared’ into the head of the page before they’re available anywhere else. I removed any other instances of these styles from the page so the only place they exist is in the PHP. I just put a simple HTML item on the page, styled one word each of the three styles and now my PHP is styled again.

I’ve learnt something today - many thanks!

Apart from putting some styled text on the page, how do I go about adding the Styles to the Head?

'k


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 30, 2012, at 8:10 AM, Kim wrote:

I have created some PHP content which will be displayed via a Markup item. The code works fine but I’m having a lot of trouble getting the formatting/style correct. It’s a news feed from a database and I want to have a heading (heading_style), story (body_style) and a ‘read more’ button (read_more_style).

To get the style tags I created a simple html item and styled things as I wanted. I then copied the styles into the echo command of my PHP and things worked for a while. I created some additional styles and somehow my PHP styles broke. No amount of tinkering has been able to get them working again.

Can you post a link to the page, or use Pastie or Gist to post the source code (scrub your passwords!) so we can see what the server or browser sees? It’s hard to say.

A few questions.
Are styles reliable? I have done a few things which have behaved oddly and I’m not sure whether it’s my inexperience or whether they’re perhaps a bit fiddly.

Styles that you have applied elsewhere in the page will always publish into the page, and thus be available to the other non-Freeway code on the same page. Styles that you have published on a different page will be available to all pages if you are using the External Stylesheets feature (Document Setup / Output). Styles that are not applied to any other element on the page will not be published into the page head unless they are “Tag-only” styles.

I made the TemplateHelper Action to help out with this issue. Basically, it allows you to create a “scratch” element somewhere on the page, place instances of all the styles you need to be in that page within it, and then erases that element from the page during publish (so it isn’t left hanging around off-screen – or drifting into screen in the case of a centered page and a huge browser window). You might want to check that out if you can’t get the styles to stick around otherwise.

Should I have a style applied to the Markup item if I want the styles to come from the PHP?

Please explain what you mean by “come from PHP”. Are these styles defined as classnames, like class=“foo” in the PHP source? Or are you writing a long-hand style tag, like style=“text-size:30px; color:red;” in your PHP?

Will a Page style affect my Markup item?

Markup items are completely unaware of their contents, and depending on how you apply them to the page (inline vs stand-alone) may not actually emit any code of their own. What can happen in cases where you are using them inline is that you may end up with an invalid construction. Say your PHP creates a div with some nested lists inside it, but you used an inline Markup Item to inject that into an HTML box on your page. What you end up with is

  • Your PHP-generated list

. So you’ve nested a div inside a paragraph, which is illegal. Browsers generally figure this out and deal with it, but any CSS that’s relying on a specific order of tags will fail.

Should the styles in the PHP override anything else which is set?

CSS (regardless of where it originates) will depend mostly on the specificity of the style rules to determine where any given rule applies. So a bare class selector, like .foo { color: blue } would be overridden by a more specific rule, like div.foo { color: red }. That’s within the same style sheet or page head, for a start.

Then you also have inline style tags, like

content
. In that case, the style attribute closest to the content (i.e. within the div tag itself) has the best chance of defining what you see. (Yes, there are exceptions to this, but for purposes of explanation, it is a fair statement.)

Any assistance or tips would be greatly appreciated. I’m having a great time experimenting with Freeway and this seems to be the last stumbling block as just about everything we do runs via PHP.

The issue will not be anything to do with PHP, or Freeway, but rather with what the combination of them create. In the end, the browser only sees HTML and CSS, so your first place to start looking at this problem in depth is in your browser, while viewing the site from your server, using the Develop menu in Safari to inspect the source and the rendered DOM.

Walter

'k


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,

Many thanks for the thorough response. A comment Deltadave made alerted me to the issue of needing the styles declared and i now have them working again.

Styles that you have applied elsewhere in the page will always publish into the page, and thus be available to the other non-Freeway code on the same page.

This was part of what I didn’t understand. I had deleted all other instances of these styles from the page so the only place they existed was in the PHP.

Styles that you have published on a different page will be available to all pages if you are using the External Stylesheets feature (Document Setup / Output). Styles that are not applied to any other element on the page will not be published into the page head unless they are “Tag-only” styles.

I’ll have to look this up in the manuals but it sounds interesting.

I made the TemplateHelper Action to help out with this issue. Basically, it allows you to create a “scratch” element somewhere on the page, place instances of all the styles you need to be in that page within it, and then erases that element from the page during publish (so it isn’t left hanging around off-screen – or drifting into screen in the case of a centered page and a huge browser window).

Perfect, this is exactly what I need. Will give it a shot in the daylight hours.

'k


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options