News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to put hashes before each tag listed, or commas after

Started by wynnyelle, June 22, 2013, 10:07:15 PM

Previous topic - Next topic

wynnyelle

http://warriorcatsrpg.com/index.php?topic=1132995.new#new

Scroll to the bottom and you see that the tags are all sort of hard to distinguish. It might help if they got a hash in front of each one and it would distinguish where it started and ended. Or, alternately, a comma after each tag. Or both. Would it be at least fairly easy to do it? I know where the language file is so if it's through there I'd just need a tip on how.

kat

What code are you using, for that?


kat

Ah, right. Well, not trying to pass the ol' back, or anything, here. But, it might be best to ask him, then, in the support topic for the mod. After all, he knows how it's coded. :)

IchBin™

In your Display.template.php file find this code:

foreach ($context['topic_tags'] as $i => $tag)
{
echo '<a href="' . $scripturl . '?action=tags;tagid=' . $tag['ID_TAG']  . '">' . $tag['tag'] . '</a>&nbsp;';
if(!$context['user']['is_guest'] && allowedTo('smftags_del'))
echo '<a href="' . $scripturl . '?action=tags;sa=deletetag;tagid=' . $tag['ID']  . '"><font color="#FF0000">[X]</font></a>&nbsp;';

}


In the first echo statement you can add a comma right at the end before the &nbsp; :

foreach ($context['topic_tags'] as $i => $tag)
{
echo '<a href="' . $scripturl . '?action=tags;tagid=' . $tag['ID_TAG']  . '">' . $tag['tag'] . '</a>,&nbsp;';
if(!$context['user']['is_guest'] && allowedTo('smftags_del'))
echo '<a href="' . $scripturl . '?action=tags;sa=deletetag;tagid=' . $tag['ID']  . '"><font color="#FF0000">[X]</font></a>&nbsp;';

}
IchBin™        TinyPortal

emanuele

* emanuele whistles innocently

The &nbsp; would potentially make the line a bit long (IIRC 40 tags per topic are allowed).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

IchBin™

Not sure what you are saying ema. There's a space after each tag. They only want a comma or somethings to make the spacing a little more apparent.
IchBin™        TinyPortal

MrPhil

The nbsp's are between individual tags. Individual tags have spaces between words. The list will therefore always break in the middle of a tag, rather than between tags. If all or most of the tags are single words, there will be a problem as @emanuele points out, because there will be few or no blanks to break on, and a line could get too long. You probably would want to have nbsp's within a tag, and blanks between the tags. Adding a # before or a , after a tag is a separate issue.

emanuele

Quote from: IchBin™ on June 24, 2013, 10:59:57 AM
Not sure what you are saying ema. There's a space after each tag. They only want a comma or somethings to make the spacing a little more apparent.
* emanuele blames the small monitor.
* emanuele whistles innocently...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

IchBin™

Quote from: MrPhil on June 24, 2013, 12:24:07 PM
The nbsp's are between individual tags. Individual tags have spaces between words. The list will therefore always break in the middle of a tag, rather than between tags. If all or most of the tags are single words, there will be a problem as @emanuele points out, because there will be few or no blanks to break on, and a line could get too long. You probably would want to have nbsp's within a tag, and blanks between the tags. Adding a # before or a , after a tag is a separate issue.

Am I dense on this? I still don't see it Phil sorry. The tag name is output with the $tag['tag'] inside the link. The nbsp is at the end, after the link. Putting a comma there would not break anything. It would put it after the tagname of the link. It should not have anything to do with a tag name with spaces in it. Although, after closer inspection I see it will look odd for anyone that has permission to delete a tag with the comma being after the tag, but before the [X] delete link.
IchBin™        TinyPortal

MrPhil

Quote

    Reply
    Unsubscribe

Pages: 1 ... 4 5 6 [7]   Go Up
Tags: tag test tags viz is adding tags tag question? more tags tag help tag problems tag improvements site requests the most tags evurr #YOLO lol #juliaisviz #juliaisnotjulia #wynnispronouncedwin that awkward moment? Cedar cool test moartest LiveLikeLarry hashtag tagsareawesome
+ Reply 

<b>Tags: </b>
<a href="http://warriorcatsrpg.com/index.php?PHPSESSID=1639df9b49de8036110d4415c8edf608&amp;action=tags;tagid=1121">tag test</a>&nbsp;
<a href="http://warriorcatsrpg.com/index.php?PHPSESSID=1639df9b49de8036110d4415c8edf608&amp;action=tags;tagid=359">tags</a>&nbsp;
<a href="http://warriorcatsrpg.com/index.php?PHPSESSID=1639df9b49de8036110d4415c8edf608&amp;action=tags;tagid=1122">viz is adding tags</a>&nbsp;
<a href="http://warriorcatsrpg.com/index.php?PHPSESSID=1639df9b49de8036110d4415c8edf608&amp;action=tags;tagid=1123">tag question?</a>&nbsp;
<a href="http://warriorcatsrpg.com/index.php?PHPSESSID=1639df9b49de8036110d4415c8edf608&amp;action=tags;tagid=1124">more tags</a>&nbsp;
<a href="http://warriorcatsrpg.com........


Blanks within tags (links), and nbsp between tags. If you hover over the tag list, you'll see the highlighted multiword tags, and the lines breaking within tags, not between.

IchBin™

But that doesn't break the link. A line may break between the space on a tag when it hits the edge of the page, but it's still comma separated between each tag this way. If I'm still not seeing the issue, maybe I won't until I install it and see what it really looks like. lol
IchBin™        TinyPortal

MrPhil

The link is split into two pieces, each with one or more words, if it is at the end of the line. True, each piece still functions perfectly well, but it doesn't look very good. The nbsp's force the links to break in the middle (at the blanks). Just look at the tag examples in the first post. Just as a matter of neatness, I would exchange the blanks in the tags for nbsp's, and use blanks between the links, so that tags don't get split across lines, but stay together as units. If tags could be unreasonably long, you might leave the blanks in them as-is, and accept that some tags are likely to break at line ends, but lines are more likely to be more or less filled.

wynnyelle

Thanks for the responses everyone!

How would I put a hash before each tag, but only if the tag didn't already start with a hash?

MrPhil

In the code that assembles this tag area, you will at some point have each individual tag (text and link). Simply look at the tag text and add a # if it doesn't already start with one. Something like

if (!preg_match('/^#/', $tag_string)) $tag_string = '#'.$tag_string;


or

if (substr($tag_string, 0, 1) != '#') $tag_string = '#'.$tag_string;

emanuele

Why a regex to check just if there is one specific char? :P

if ($tag_string[0] != '#') $tag_string = '#'.$tag_string;

BTW is *bad* do this kind of checks in the template (dunno know if you were suggesting to do it there or not, just saying), much better prepare the strings properly in source.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

wynnyelle

I have learnt that using &nbsp; to create a space should be avoided, instead CSS should be used. How would that be done?

MrPhil

Say what? I've never heard of using CSS to create a space, at least in the sense of space between items on a line. Maybe a span with some padding, but that's the long, long way around the garden path. The difference between a blank/space and a nonbreaking space (&nbsp;) is that while they look the same, the blank/space can be thrown away and the line wrapped (cut) there. &nbsp; is a normal character (that can't be thrown away), but looks like a blank/space. Multiple blanks/spaces in a row are allowed to be chopped down to just one. Both are useful; you just need to learn which is appropriate for what you're doing. A &nbsp; is good for keeping related words together on one line: e.g., Mr.&nbsp;Jones will never be split over two lines.

emanuele

Obviously there are different cases.
In that case a nbsp (as I already wrote previously) would create a *long* line (as it already happened) of tags.
Obviously a nbsp is a very poor choice for spacing things (and that's just bad design of the mod I wonder why you would chose a nbsp to separate a list...heck I don't even understand why not a list, but that's another point). Yes, there are cases where you can't use anything else, but if everything you want is just a bit more spacing between two consecutive elements (and the tags in that case are all <a> tags) a tune of the padding is by far the most sensible way to do it.
Heck I even suggested to use css to add the comma between tags and the hash before each tag: no need to edit template nor source files, no need to disrupt the service even for just a split of second (that on a forum with so many users as Groovy's would mean quite a bit of pain and errors in the logs). Win-win.
#tags_list a {
padding: 0 0.2em;
}
#tags_list a:not(:last-child):after {
    content: ',';
}
#tags_list a:before {
    content: '#';
}


ETA: yes, the id tags_list is something I added to the container of the tags in order to be able to style it (something that would have been nice to have in the original mod directly :P).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

MrPhil

"Use &nbsp; to separate a list?" That would be unusual. To replace spaces within a list item, so that the list item doesn't get broken across line ends, yes, but not to separate list items.

Your CSS solution assumes that all his members have CSS3-capable browsers. More importantly, the list must be built as a list (ul) and not as item item item item text (inline or paragraph style list). In this particular case, I believe that the list is paragraph style.

Advertisement: