开发者

How can I style a string or substring placed into a Drupal node field?

开发者 https://www.devze.com 2023-04-02 13:44 出处:网络
In Drupal 6, I have a custom node that consists of j开发者_运维知识库ust one plaintext field.

In Drupal 6, I have a custom node that consists of j开发者_运维知识库ust one plaintext field.

I'd like to be able to detect the following string: "@[name]" where [name] is a string with no whitespace. Ideally, it would be nice to wrap this text in a span with an id, so I can then style it as I wish. The main challenge is that the string is not fixed, so could be any arbitrary peice of text.

Is there a module that exists for this type of thing, or can I implement with hooks? I looked at String overrides, but that's only for fixed strings.


You can just create a custom template for that content type. Then you can wrap the field in any element you like and make the node look however you like as well. Take a look at the following example of theming custom content types: Example: Theming a Specific CCK Content Type


Provided that you're using Views to display your field and PHP code is enabled, you should be able to put @[name] within a span or a div by selecting "Rewrite output of this field" and using regular expressions to return the string you need to highlight.

Finding the RegEx shouldn't prove to difficult, it would probably be something along the lines of:

Find the character "@" followed by any number of characters

Sorry, I don't use RegEx often enough to give you the exact code, but it shouldn't take you long to find out.

Then it's only a question of returning the string and adding some tags.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号