HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Username variable returns unknown in welcome message

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#99980 (In Topic #19625)
TQ
Avatar

Honoured member

Hi All,

If I place:

Code

{$USERNAME,{MEMBER_ID}}

... in my welcome message, the user gets a message addressed to:

Dear Unknown,

Should I be adding something else to the message to identify the user first?

Nick
Back to the top
 
Posted
Rating:
#99982
Avatar

Community saint

TQ said

Hi All,

If I place:

Code

{$USERNAME,{MEMBER_ID}}

… in my welcome message, the user gets a message addressed to:

Dear Unknown,

Should I be adding something else to the message to identify the user first?

Nick


I think the way the welcome emails are handled (in sources/hooks/systems/cron/ocf_welcome_emails.php), it would not be possible to specify a username without some programming changes. It looks like the welcome emails are more generic and any member-specific tempcode won't work. The actual text of the welcome email is stored in the database and doesn't have any knowledge of what the member ID is when it gets processed, so it just returns Unknown. 

This is completely off the top of my head and untested, but one of these two ideas might work... Start by making a copy of sources/hooks/systems/cron/ocf_welcome_emails.php in the sources_custom/hooks/systems/cron directory (this creates an override so we don't tamper with the original). When making the edits below, be sure to modify the ocf_welcom_emails.php that is under the sources_custom directory.

First idea... I'm not sure exactly when the tempcode of the $text variable gets evaluated or the order in which things get evaluated in the do_template function. If it gets evaluated after all variables are place into and made available to the tempcode object in the do_template function, it may be possible to simply add the MEMBER_ID variable to the template by changing this line (should be at or near line 74):

Code

$_text=do_template('NEWSLETTER_DEFAULT_FCOMCODE',array('_GUID'=>'8ffc0470c6e457cee14c413c10f7a90f','CONTENT'=>$text,'LANG'=>get_site_default_lang()));

to:

Code

$_text=do_template('NEWSLETTER_DEFAULT_FCOMCODE',array('_GUID'=>'8ffc0470c6e457cee14c413c10f7a90f','MEMBER_ID'=>strval($member['id']),'CONTENT'=>$text,'LANG'=>get_site_default_lang()));

If that works, no other changes are necessary, but I suspect it won't work. I think I had a similar issue using .ini strings with tempcode in them and, when passing them to the template, they didn't evaluate as I wanted them to with the Downloads Follow-up Email addon.

Idea two... Copy and insert this line of code:

Code


$text=static_evaluate_tempcode(do_lang_tempcode($text, $member['id']));

between these two lines of code (should be at or near lines 74 and 75):

Code

$text=get_translated_text($mail['w_text'],NULL,get_lang($member['id']));
$_text=do_template('NEWSLETTER_DEFAULT_FCOMCODE',array('_GUID'=>'8ffc0470c6e457cee14c413c10f7a90f','CONTENT'=>$text,'LANG'=>get_site_default_lang()));


Then, in your welcome message, change the {$USERNAME,{MEMBER_ID}} to {$USERNAME,{1}}.

If I'm understanding the functions correctly, what I think this will do is take the welcome email text string from the database and turn it into a tempcode object and insert the member ID into the {1} placeholder of the welcome email text. Then it takes the tempcode object and converts it back into a string that gets passed into NEWSLETTER_DEFAULT_FCOMCODE template.

If you try either of these and they don't work, don't forget to remove the sources_custom/hooks/systems/cron/ocf_welcome_emails.php override file!

As a side note... As I mentioned above, I think this is the same issue I wrestled with in the Downloads Follow-up Email addon. But instead of getting the message body from the database, I was getting it from a language .ini file. I couldn't quite get the language .ini string to evaluate the way I wanted, so I moved it all to the template until I can get that part figured out. The big drawback to placing it all in the template instead of using the language .ini file is that it removes the ability to customize the message body for multi-language web sites.
Back to the top
 
Posted
Rating:
#99983
TQ
Avatar

Honoured member

Thank you very much Jason, I will check it out and report back.
Nick
Back to the top
 
Posted
Rating:
#99984
Avatar

As long as you have newsletters installed, welcome emails will piggy-back off the templating code for that (regardless of whether the welcome email is being sent to members or to a newsletter). This functionality is as described in the newsletters tutorial but basically it means you can use things like {name} in there.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#99985
Avatar

FYI Jason, the newsletters / welcome e-mails don't use proper Tempcode for putting in the member-specific data, for performance reasons (if you're e-mailing thousands of people, doing a template reevaluation for each isn't ideal). So we cheat. The newsletter_variable_substitution function does simple string substitution. It looks a bit like Tempcode, but we make clear it's not via the lower-case parameters (Tempcode is always upper-case).

The big drawback to placing it all in the template instead of using the language .ini file is that it removes the ability to customize the message body for multi-language web sites.

Yes, language strings are never written in Tempcode, again for performance reasons. We need these to come out of the system really quickly as we use them so much.

Usually using a combination of a template and a language string is fine; you would pass in bits of Tempcode as parameters to the language string and they would get evaluated prior to going into the string as parameters.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#99986
Avatar

Community saint

Thanks for the info Chris. That makes sense. I didn't notice the newsletter_variable_substitution. I hadn't looked quite that far down the code.

So Nick, it looks like you just replace {$USERNAME,{MEMBER_ID}} in your welcome message with {name} and you should be good to go.
Back to the top
 
Posted
Rating:
#99996
TQ
Avatar

Honoured member

Thanks to you both.

The {name} variable worked a treat and thanks Chris for further insight on how OCP works.

I'm sorry if I'm asking questions that I could have answered using the help system but the enormity of OCP means I miss the obvious sometimes. I think you'll have to either kick me out or brace yourselves for more of the same because OCP has really captured my imagination. Great software and great community, who could ask for more?

Nick
Back to the top
 
Posted
Rating:
#99997
Avatar

Actually I tend to only jump in on these kinds of queries myself when I have realised the official documentation is insufficient ;) (or if exploring a possible bug or usability issue). I then update the docs in parallel to answering the topic :). So that's what happened here, the documentation wasn't sufficient, and will be updated probably come next patch release.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#99998
TQ
Avatar

Honoured member

Your diligence is to be commended. Nick
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: