Add Some Extra Text To Only Selected Views

I need to insert some extra text in the beginning of view content (so, inside layout). Or execute particular code only for certain controllers/actions. [size=“2”]But I don’t know what would be best practice to select views (controllers/actions) for which this text is added?[/size]

[size="2"]For example, I want to execute piece of code or add some text to the view only for so called "front-end" part of my app. So I need to get somehow, which controllers are for which part. And what about controllers that are used for both sides. For example, my UserController is used for managing users, acts for backend [/size][size="2"]and therefore[/size][size="2"] should not display extra text / execute extra code. But the same controller has also login action, which is part of frontend and for this one action, text should be displayed or code should be executed.[/size]

I was thinking about beforeAction (or eventually beforeRender). But I’m not sure, if this is the correct way. Maybe behaviors would be better here?

If behaviors, then do I have to manually attach behavior to each controller/action, that should display extra text (and if yes, then how to do this)? Or is there any central-way of solving this problem, where I could for example use beforeAction in base controller and check there somehow, whether particular action belongs to frontend or backend.

Generally, I’m not looking for a clean, ready-to-use solution, but rather an advice, would would be best practice in solving this problem?