Fossil Forum

torstenberg 1 month ago

Post: Use TH1 in Ad-units

Currently, the Ad-unit uses plain HTML. What I want to have is different "Ad-units" on different pages.

As an example, having an announcement on the main page is fine but I do not want to see it on e.g. the "Branches" or "Tags" page, let alone the "Admin" page. Nonetheless, I might want to have a different text (or image) depending on some conditions such as the page or whether someone is logged in or not. I am also thinking of having some permanent text on the Forum page telling people how to use it or what to remember when using it. So, in the end, this Ad-unit can just as well serve as a general customizable placeholder after the menu and before the content.

After having looked into this, the change needed in the code seems trivial and does not change the trust level either (the skin header and footer already use TH1). In the function style_finish_page() in src/style.c (starting on line 980), we just need to replace the two cgi_append_content() calls with Th_RenderToBlob():

/* line 1117 before */
cgi_append_content(zAd, -1);

/* line 1117 after */
Th_RenderToBlob(zAd, NULL, TH_R2B_NO_VARS);

This would change the "adunit_banner" part. The same could, of course, be done for the "adunit_right" part.

As far as I can see, the following TH1 variables will the be accessible:

| TH1 variable | Example value | |---|---|---| | $current_feature | forum, home, wiki, timeline | | $current_page | forumpost/abc123 | | $requested_page | forumpost | | $login | alice (unset for anonymous) | | $project_name | My Project |

For the current Ad-unit, nothing will change, they will continue to work as always. Only when wanting to use more customization, admins will change the HTML to include some TH1. Here's an example:

<th1>
if {$current_feature eq "home"} {
  html {<div class='announcement'>
    <strong>&#x1F4E2; Announcement:</strong> v2.0 released!
    <a href='} $home {/wiki/release-notes'>Read the release notes.</a>
  </div>}
} elseif {$current_feature eq "forum"} {
  html {<div class='important-notice'>
    <strong>&#x26A0;&#xFE0F; Forum notice:</strong>
    Please search before posting a new thread.
  </div>}
} elseif {$current_feature eq "timeline"} {
  # No ad on the timeline
} else {
  # Default: real ad unit on all other pages
  html {something else here}
}
</th1>

If there is no objection, I can do the change and also update the documentation , using a new branch which then can be reviewed and merged by the core team later.

torstenberg 4 weeks, 1 day ago

Currently, the Ad-unit uses plain HTML. What I want to have is different "Ad-units" on different pages.

As an example, having an announcement on the main page is fine but I do not want to see it on e.g. the "Branches" or "Tags" page, let alone the "Admin" page. Nonetheless, I might want to have a different text (or image) depending on some conditions such as the page or whether someone is logged in or not. I am also thinking of having some permanent text on the Forum page telling people how to use it or what to remember when using it. So, in the end, this Ad-unit can just as well serve as a general customizable placeholder after the menu and before the content.

After having looked into this, the change needed in the code seems trivial and does not change the trust level either (the skin header and footer already use TH1). In the function style_finish_page() in src/style.c (starting on line 980), we just need to replace the two cgi_append_content() calls with Th_RenderToBlob():

/* line 1117 before */
cgi_append_content(zAd, -1);

/* line 1117 after */
Th_RenderToBlob(zAd, NULL, TH_R2B_NO_VARS);

This would change the "adunit_banner" part. The same could, of course, be done for the "adunit_right" part.

As far as I can see, the following TH1 variables will then be accessible:

| TH1 variable | Example value | |---|---|---| | $current_feature | forum, home, wiki, timeline | | $current_page | forumpost/abc123 | | $requested_page | forumpost | | $login | alice (unset for anonymous) | | $project_name | My Project |

For the current Ad-unit, nothing will change, they will continue to work as always. Only when wanting to use more customization, admins will change the HTML to include some TH1. Here's an example:

<th1>
if {$current_feature eq "home"} {
  html {<div class='announcement'>
    <strong>&#x1F4E2; Announcement:</strong> v2.0 released!
    <a href='} $home {/wiki/release-notes'>Read the release notes.</a>
  </div>}
} elseif {$current_feature eq "forum"} {
  html {<div class='important-notice'>
    <strong>&#x26A0;&#xFE0F; Forum notice:</strong>
    Please search before posting a new thread.
  </div>}
} elseif {$current_feature eq "timeline"} {
  # No ad on the timeline
} else {
  # Default: real ad unit on all other pages
  html {something else here}
}
</th1>

If there is no objection, I can do the change and also update the documentation , using a new branch which then can be reviewed and merged by the core team later.

stephan 4 weeks, 1 day ago

If there is no objection, I can do the change and also update the documentation , using a new branch which then can be reviewed and merged by the core team later.

Please do!

torstenberg 1 week, 2 days ago

Done now in commit 6ac7935a71ef9d72 on the new branch th1-ad-unit.

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button