Need to change the contents of this one table. Need help ASAP

Started by wynnyelle, June 25, 2012, 01:48:36 AM

Previous topic - Next topic

wynnyelle

I finally found what needs to change but I don't know how to change it.

Here's the code in index.template.php:


// Time for the our news!

echo'<div class="pnl"><div class="newsDiv">

<div class="newsText">

', (!empty($modSettings['news_text']) ? parse_bbc($modSettings['news_text']) : ''), '

</div>

</div>';



// If the user is logged in, display stuff like their name, new messages, etc.


It produces the text that gets dropped into my custom newstext area on every page of my site,under the logo and menu on the right side {the right one of two twin tables}. I want to change what text and links are shown in it but I don't know how. It's calling it from the database and I know how to go in and change it there, but that would only change it for every single theme I have.

I need a little help on this ASAP please....I don't care what method I wind up needing to use I just need to be able to change it. I would try just putting it all in PHP on that file itself but I don't know how.

MrPhil

What you have now is
div.newsDiv
    div.newsText
       (blank) if settings table entry 'news_text' is empty, otherwise
       BBCode-parsed 'news_text' entry

What do you mean by "I want to change what text and links are shown in it"? Are you looking to change it (the "News") the same for all themes, or just for specific theme(s)? As you noted, it's in the database, so there should be an interface in Admin for changing the news (it will affect all themes that display the news). If you're looking for different news for different themes, that would be tougher (but still possible). Please clarify.

wynnyelle

We use a custom news table and don't use the one in the admin panel, but I want to change this stuff by individual skin, not change it for all the skins. I already know how to go in and change what it says by going into phpmyadmin and just changing the text from there. For the skins I want to say something different that will not work because it would change all the skins.

MrPhil

So you want different News content per theme (skin)? You would need two things:

  • a separate database entry for that theme's news (as well as the interface to update news_text_theme1, news_text_theme2, etc.). So you would have $modSettings['news_text_skin1'], $modSettings['news_text_skin2'], etc. floating around. The toughest part would be generalizing the news_text code to handle an arbitrary number of themes (skins) rather than just one of fixed name.
  • different code in a theme-specific file (Themes/<theme name>/index.template.php) that could hard-code the news name for each theme (perhaps just use the theme name itself, so it would be something like $modSettings['news_text_' . $themeName])

Anyway, that would be one way to approach it.

wynnyelle

Would it be at least relatively easy to just create a new news table per skin in the database? I could do it that way, if it is safe. I just don't know how as I've never made new tables in there before.

I was thinking also to just write each one' text out in the index.template.php since these are more information than news, and wouldn't have to be changed all that often.

MrPhil

If you were going to have a table per skin (theme), there would be only one entry per table, wouldn't there? Plus, you would have to write all the database code to handle it, instead of piggybacking on the current forum-wide news. Even a new table dedicated to nothing but news (shared by all skins) would require you to write all the code from scratch.

If it's rarely going to change, it's not really "news", but it might then be easier just to hard code it in each theme's index.template.php (or wherever the news is displayed).

The Craw

I believe she is referring to the div that contains the news text when she says "table". Not, in fact, a database table.

wynnyelle

I actually did mean the MySQL table. That's how I handle this one div's contents that get broadcasted to all of the skins on my site. I don't want it to do that for all the skins because some of the skins are set to specific boards that that text and links just doesn't apply to.

I don't care how this is accomplished, really the method is all one to me, I just need to know how to be able to set some of the skins so they aren't pulling the text and links from this one table in the database. Either by creating the text right there in the index.template.php or by creating a different table in phpmyadmin and directing that skin to that table instead. I don't know how to do either one.

wynnyelle

Anybody who can just give me the basic tips on how to just programme simple text and text links into the index.template.php file I would be SO thankful! Please, anyone...

The Craw

If it were me, I'd create a langue file with the strings you need and load it with your themes. That would save a database query, and still be easy to edit. You can load a langue file for each of your themes individually by creating a directory "languages" in each of your theme folders if it doesn't already. And inside that directory, put a file called "ThemeStrings.english.php" Inside that file, you'll want to create the strings you want, which should look something like the following.


<?php
$txt
['custom_board_desc'] = 'Ohai, this is theme specific text.';


Note that if the file or folders already exist, don't replace them, just add onto what's there. Now, in the index.template.php file in each of your themes, you'll have to find this:


/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = false;


And replace it with this:


/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = true;


That will load the contents of the ThemeStrings.english.php file, which you can then use in the template by calling the $txt key: $txt['custom_board_desc'] like so:


// Time for the our news!

echo'<div class="pnl"><div class="newsDiv">

<div class="newsText">

', (!empty($txt['custom_board_desc']) ? parse_bbc($txt['custom_board_desc']) : ''), '

</div>

</div>';



// If the user is logged in, display stuff like their name, new messages, etc.


This is probably simpler than creating a database table, and better than "hardcoding" the strings in.

wynnyelle

OMG it would be! I feel so dumb I didn't think of that! Editing language files is easy by comparison, and safer. Thank you so much!

I'll give it a whirl over on my dev site. How do I insert links into the text in this way though?

BTW I get a lot of "themestrings" errors on my site, in the error log, does it have to do with this interaction?

The Craw

Quote from: Groovystar on June 26, 2012, 03:30:50 AM
OMG it would be! I feel so dumb I didn't think of that! Editing language files is easy by comparison, and safer. Thank you so much!

I'll give it a whirl over on my dev site. How do I insert links into the text in this way though?

BTW I get a lot of "themestrings" errors on my site, in the error log, does it have to do with this interaction?

You can do links in BBC, because the text string is run through the parse_bbc() function in the template.

Those errors could be related. I'd need to see the exact errors to know for sure.

wynnyelle

So  I write out the whole thing in BBC in the language file? It'll actually work that way?

Sorry--I just thought that wasn't quite right. :P

I'll see if I can pick up  any of those errors to show you tonight.

Sorry about the questions. I just still don't know how to actually write the text into the language file that I want to show up on the site itself on that skin. I'm still not understanding.

The Craw

Your language file would look something like this.


<?php
$txt
['custom_board_desc'] = '
Hello, here is some interesting thing for you to read.
Please have a look around and feel free to join.
You can have a look [url=http://warriorcatsrpg.com/index.php?topic=1324]here[/url] for more information.

Enjoy your stay. :)'
;


Notice how the text string contains the BBC link tags. ;)

wynnyelle

Thank you so much, again!

Time for me to get brave and try this all out for myself :)

The Craw

Good luck! It isn't that complicated, so I'm sure you can handle it. :)

wynnyelle

Quote from: The Craw on June 26, 2012, 02:43:03 AM
Now, in the index.template.php file in each of your themes, you'll have to find this:


/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = false;


And replace it with this:


/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = true;



This does not exist in my file. I spent a lot of time looking for it, and text search didn't turn it up either.

wynnyelle

So I put "true" into the one that looked the most like it. This isn't working. The news box is blank, even though I put the text I wanted into the theme strings file.

I guess I'll still air the skin since a blank box is better than one filled with cat links on a board about dogs :P Still not what I want though, I want to put information on how to roleplay on that one specific board.

Thanks anyway.

The Craw

Hmm, I even downloaded an RC3 version to make sure it was there. Try adding that segment to the template_init() function.

Find:

function template_init()
{
global $context, $settings, $options, $txt;


Add After:

/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = true;

wynnyelle

It worked! After I cleared the cache, it showed up :)

Thank you SO MUCH!!

Advertisement: